std::remove_if

#include 
#include 
#include 
using namespace std;
void printv(vector v)
{
    cout<<"sizeof v: "< v = {7, 5, 16, 8};
 
    // Iterate and print values of vector
    printv(v);
    
    auto itr = std::remove(v.begin(), v.end(), 16);
    printv(v);
    
    v.erase(itr, v.end());
    printv(v);
}

输出

sizeof v: 4 { 7, 5, 16, 8, }
sizeof v: 4 { 7, 5, 8, 8, }
sizeof v: 3 { 7, 5, 8, }

你可能感兴趣的:(std::remove_if)