std::vector ints;
// ... fill ints with random values
for(std::vector::iterator it = ints.begin(); it != ints.end(); )
{
if(*it < 10)
The call to pop_back() removes the last element in the vector and so the iterator to that element is invalidated. The pop_back()
call does not invalidate iterators to items before the last element, only reallocation will do that. From Josuttis' "C++ Standard Library Reference":
Inserting or removing elements invalidates references, pointers, and iterators that refer to the following element. If an insertion causes reallocation, it invalidates all references, iterators, and pointers.