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

Remove First and Last Character C++

Well, you could erase() the first character too (note that erase() modifies the string): m_VirtualHostName.erase(0, 1); m_VirtualHostName.erase(m_VirtualHostName.size() – 1); But in this case, a simpler way is to take a substring: m_VirtualHostName = m_VirtualHostName.substr(1, m_VirtualHostName.size() – 2); Be careful to validate that the string actually has at least two characters in it first…

tech