If you use g++, you should define _GLIBCXX_DEBUG in debug mode. Then you would have received an error message such as this:
error: attempt to dereference a past-the-end iterator.
Besides that you're trying to dereference itr even though it could equal end() after the previous line, you're also skipping the element right after each 14 - two consecutive 14s can't be found. This fixes both problems (although not advancing the iterator until the next iteration would be better instead of going back):
1 2
if (*itr==14)itr=--vect.erase(itr);
else cout << *itr << " ";
Oh, and you should use operator!= when doing the check for end() - it will work with all iterators, which can't be said for operator<.
Thanks for reply. So it means, at one loop, we can delete only one element (except some range). We can not delete two element in one loop? if yes, then can you please explain why?