Remove Vector elements by position

Sep 26, 2012 at 11:36am
Hi,

How can i remove the vector elements by position,like

MyVect.erase (MyVect.at(1));

thanks in advance
Sep 26, 2012 at 11:43am
MyVect.erase( MyVect.begin() + 1 );
Sep 26, 2012 at 11:44am
erase() takes an iterator to the element to be deleted as argument. You can use begin() to get an iterator to the first element in the vector. You can then use operator+ on the iterator to make it point to a certain object.

This code will erase element at position i:
MyVect.erase(MyVect.begin() + i);
Topic archived. No new replies allowed.