代码
#include<iostream>
#include<vector>
using namespace std;
void testDelete(vector<int>& vec, const bool delete45, const bool delete_less7)
{
if (delete45 == true) {
vec.erase(std::remove(vec.begin(), vec.end(), 45), vec.end());
}
if (delete_less7 == true)
{
vec.erase(
std::remove_if(vec.begin(), vec.end(), [](int i) {return i < 7; }),
vec.end());
}
}
int main()
{
vector<int> a{ 3,1,23,45,2,7 };
testDelete(a, true, false);
for (auto item : a) {
cout << item << " ";
}
cout << endl;
testDelete(a, false, true);
for (auto item : a) {
cout << item << " ";
}
cout << endl;
return 0;
}