"thomas" <FreshThomas@gmail.com> a écrit dans le message de news:
c69c72bd-a326-4bc5-b1ef-4dd03288d4f4...oglegroups.com...
>
>> (And the higher-level answer to his question is that he should probably
>> be using std::remove anyway:
>>
>> s.erase(remove(s.begin(), s.end(), 3), s.end());
>>
>
> What's this?
> will "s.erase()" get all the elements after "3" removed?
remove will remove all element equal to 3. beware, removing is not
erasing... Remove returns an iterator to the new end of the sequence s (it
does not actually modify s.end() ) , so you can use this iterator in the
vector::erase function. The size of the vector is not modified after a
remove, but the element between the returned end and the actual s.end() but
the element are unspecified.
so you can do
vector<int>::iterator NewEnd = remove(s.begin(), s.end(), 3);
s.erase(NewEnd, s.end);
Eric Pruneau