If you are erasing while iterating, consider this syntax:
vector<int> items = ...; for(vector<int>::iterator it = items.begin() ; it != items.end() ; /*inline*/) { if(/* should erase*/) it = items.erase(it); else ++it; }
This works because erase() returns an iterator to the next element after the current one. So, if you erased, it gets 'incremented', otherwise, you increment it like normal. As others have noted though, this is not very efficient (since all elements after the current one are copied forward), and there are better ways. For example, as Mark B mentioned, it may be better to use remove_if.