Allegedly you cannot just erase/remove an element in a container while iterating as iterator becomes invalid. What are the (safe) ways to remove the elements that meet a cer
bool IsOdd( int i ) { return (i&1)!=0; } int a[] = {1,2,3,4,5}; vector v( a, a + 5 ); v.erase( remove_if( v.begin(), v.end(), bind1st( equal_to(), 4 ) ), v.end() ); // v contains {1,2,3,5} v.erase( remove_if( v.begin(), v.end(), IsOdd ), v.end() ); // v contains {2}