Can iterators become invalid after operations?

Possible Duplicate:
Iterator invalidation rules

Imagine that I have a map<int, int> . Somehow I retrieved an iterator pointing to an entry pair<35,37> in the map. I save this iterator as map<int, int>::iterator _my_iterator3537 .

After that, I did a lot of insertion to the map. Is _my_iterator3537 still pointing to the pair<35,37> ?


from documentation:

Map has the important property that inserting a new element into a map does not invalidate iterators that point to existing elements.

Erasing an element from a map also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased.

from standard: 23.1.2/8

The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.

链接地址: http://www.djcxy.com/p/73342.html

上一篇: 使用find从矢量中清除所有偶数

下一篇: 操作之后,迭代器会失效吗?