Hi,
I guess this is pretty basic, but I can't seem to sort this out right now: I'm going thru a vector with an iterator, and if get a match, want to erase the item. Something like this:
Now, if the last item is erased, the iteration goes thru one more time, with the size of v being 0, and me getting an access violation. i is not end(). How is this supposed to be done without having to check size() or empty()?
I guess this is pretty basic, but I can't seem to sort this out right now: I'm going thru a vector with an iterator, and if get a match, want to erase the item. Something like this:
Code:
for (vector<int>::iterator i = v.begin(); i != v.end(); ++i)
if ((*i) == 0)
v.erase(i);