Possible Duplicate:
Erasing an element from a container while inside a range-based for loop
Similar to this, can you delete from an STL list while iterating over it using the new for( auto item : list ) syntax?
Here's a complete example (that crashes!)
#include <list> using namespace std ; int main() { list<int> li; li.push_back( 4 ) ; li.push_back( 5 ) ; li.push_back( 6 ) ; for( auto num : li ) { if( num == 5 ) li.remove( num ) ; else printf( "%d\n", num ) ; } }
std::list.