Re: vector.erase(iterator iter) will change "iter" or not?
Just a small correction.
> vector<int> s;
> for(vector<int>::iterator iter=s.begin(); iter!=s.end(); iter++){
> if(*iter==3)
> iter= s.erase(iter);
> }
After the erase() call iter points at the next element in the
container. Thus when the iter++ is called you will effectively skip
an element or if the erased element is the last element it now points
one after end().
Also for efficiency it is a god idea to get in the habit of using
prefix increment (In this case it probably makes no difference but
for the generic case it does).
|