I have an iterator for a vector that I want to delete certain elements in the vector. Running the code, no errors come up in the compiling, but after executing I receive a message saying 'Debug assertion failed!'. Could somebody tell me what's wrong with my iterator?
int function(unsigned int n, unsigned int m) { vector<int> vec1; vec1.push_back(3); vec1.push_back(4); vec1.push_back(5); vector<int>::iterator vec2; for (vec2 = vec1.begin(); vec2 != vec1.end(); ++vec2) { if(*vec2 == 4) { vec1.erase(vec2); } } return 0; }