i think you'd better take a look at erase-remove idiom about vector.it's a efficient way to remove element in vector
erase-remove of a std::vector uses the swap and pop method, correct?
it's like that
template < class ForwardIterator, class T >
ForwardIterator remove ( ForwardIterator first, ForwardIterator last, const T& value )
ForwardIterator result = first;
for ( ; first != last; ++first)
if (!(*first == value))
*result++ = *first;
(from c++ library).
remove doesn't delete the element in the vector instead of overwriting the element like the code said.
so we must use erase to delete these elements who should be removed like that vec.erase(remove(first, end, value), end).
you can see these subjects in book named Effective STL