Do STL iterators guarantee validity after collection was changed?

前端 未结 3 430
南方客
南方客 2020-12-01 07:49

Let\'s say I have some kind of collection and I obtained an iterator for the beginning of it. Now let\'s say I modified the collection. Can I still use the iterator safely,

3条回答
  •  时光取名叫无心
    2020-12-01 08:33

    No, iterators are only good while the iterated container is unchanged. If a collection is modified, the iterator should be obtained anew.

提交回复
热议问题