Answer the question
In order to leave comments, you need to log in
Inserting data into std::vector< GLfloat >?
How can I enter data in std::vector<GLfloat>
by index, for example 1?
In Java, I have implemented this:
this.vertexBuffer.put(1, x);
How can I do the same in C ++?
Answer the question
In order to leave comments, you need to log in
Before working with its indices, the vector must be reduced to the required size.
This is done using the resize
[ ? ].
After that, you can access the value by index directly.
If the size of the vector has already been determined and it is necessary to insert data by index, then you can use the insert
[ ? ].
However, the first parameter of the method is not an index, but an iterator inside the vector where you want to insert. This iterator can be obtained by offsetting the start iterator of the vector by the required index.
vertexBuffer.insert( vertexBuffer.begin() + 1, x );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question