> In VC++ 8, iterators into vectors become invalidated whenever the number of
> elements in the vector changes. The invalidation happens immediately. The
> size of the loop is irrelevant.
>
> You can use #define _HAS_ITERATOR_DEBUGGING 0 to prevent the invalidation,
> but I don't recommend it unless you're really sure about what you're doing.
Thanks for your reply. I did know about the work-around, but I'm not
confident enough to simply apply it, especially because I don't know
what is going on here. Anyway, a simple loop pushing data onto the end
of a vector shouldn't be a problem, should it? I understand that
iterators into the vector are being invalidated by the push_back(), but
I'm not holding, nor using iterators into the vector.
--nico
Doug Harrison [MVP] - 19 May 2006 22:48 GMT
>Thanks for your reply. I did know about the work-around, but I'm not
>confident enough to simply apply it, especially because I don't know
>what is going on here. Anyway, a simple loop pushing data onto the end
>of a vector shouldn't be a problem, should it?
It will invalidate end(), but unless reallocation happens, it won't
invalidate any other iterator. You can prevent reallocation by using
reserve() beforehand.
>I understand that
>iterators into the vector are being invalidated by the push_back(), but
>I'm not holding, nor using iterators into the vector.
Can you post a small console program that demonstrates the problem?

Signature
Doug Harrison
Visual C++ MVP