469,964 Members | 1,669 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

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

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[i] (where 0<i<N) in
such a way that after the remove/delete operation MyVector.size() will be
N-1 ?
Jul 22 '05 #1
1 1348
zoom wrote:
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[i] (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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by David Lozzi | last post: by
1 post views Thread by Allerdyce.John | last post: by
1 post views Thread by rn5a | last post: by
11 posts views Thread by Richard Maher | last post: by
5 posts views Thread by barcaroller | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.