Using erase-remove_if idiom
The correct code is: stopPoints.erase(std::remove_if(stopPoints.begin(), stopPoints.end(), [&](const stopPointPair stopPoint)-> bool { return stopPoint.first == 4; }), stopPoints.end()); You need to remove the range starting from the iterator returned from std::remove_if to the end of the vector, not only a single element. “Why?” std::remove_if swaps elements inside the vector in order to put all elements that … Read more