我想删除所有将.first值设置为4的对.
stopPoints.erase(std::remove_if(stopPoints.begin(),stopPoints.end(),[&](const stopPointPair stopPoint)-> bool { return stopPoint.first == 4; }));
第二种
#include// the general-purpose vector container #include #include // remove and remove_if bool is_odd(int i) { return (i % 2) != 0; } void print(const std::vector &vec) { for (const auto& i: vec) std::cout << i << ' '; std::cout << std::endl; } int main() { // initialises a vector that holds the numbers from 0-9. std::vector v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; print(v); // removes all elements with the value 5 v.erase( std::remove( std::begin(v), std::end(v), 5 ), std::end(v) ); print(v); // removes all odd numbers v.erase( std::remove_if(std::begin(v), std::end(v), is_odd), std::end(v) ); print(v); return 0; }



