两种方法:
1、调用vector自身的erase
2、调用erase和remove
void remove_vector(vector<int>& v, int val)
{
vector<int>::iterator it = v.begin();
while (it != v.end())
{
if (*it == val)
{
it = v.erase(it);
}
else
{
++it;
}
}
}
int a[] = {1,2,3,4,5};
vector<int> v(a, a+5);
remove_vector(v,2);
v.erase(remove(v.begin(), v.end(), 3), v.end());
vector<int>::iterator it;
for (it = v.begin(); it != v.end(); ++it)
{
cout << *it << " ";
}
cout << endl;