If std::vector <TMyClass> MyVector; --> How to remove MyVector[i] ?

G

Guest

Say we have a vector defined as

std::vector <TMyClass> MyVector;

and we appended N number of element (N>1) to our vector (ie. MyVector.size()
is N)

How can we remove/delete an individual element MyVector (where 0<i<N) in
such a way that after the remove/delete operation MyVector.size() will be
N-1 ?
 
V

Victor Bazarov

zoom said:
Say we have a vector defined as

std::vector <TMyClass> MyVector;

and we appended N number of element (N>1) to our vector (ie. MyVector.size()
is N)

How can we remove/delete an individual element MyVector (where 0<i<N) in
such a way that after the remove/delete operation MyVector.size() will be
N-1 ?


Use vector::erase() member function. Make the iterator that points
to the i-th element by applying + to the result of a call to 'begin()'.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top