how are map iterators invalidated when erasing elements? [duplicate]
问题 This question already has answers here : Iterator invalidation rules (5 answers) Closed 10 months ago . when and how are iterators invalidated in a map when using the erase method ? for example : std :: map < int , int > aMap ; aMap [ 33 ] = 1 ; aMap [ 42 ] = 10000 ; aMap [ 69 ] = 100 ; aMap [ 666 ] = -1 ; std :: map < int , int > :: iterator itEnd = aMap.lower_bound ( 50 ) ; for ( std :: map < int , int > :: iterator it = aMap.begin ( ) ; it != itEnd ; // no-op ) { aMap.erase ( it ++ ) ; }