Standard C++ Library Class Reference

// remove the 7
vector<int>::iterator result =
remove(v.begin(), v.end(), 7);
// delete dangling elements from the vector
v.erase(result, v.end());
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
// remove everything beyond the fourth element
result = remove_if(v.begin()+4,
v.begin()+8, all_true<int>());
// delete dangling elements
v.erase(result, v.end());
copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
cout << endl << endl;
return 0;
}
Output :
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 8 9 10
1 2 3 4
1 2 4
Warning
If your compiler does not support default template parameters, then you need to always supply
the Allocator template argument. For instance, you will need to write :
vector<int, allocator>
instead of :
vector<int>
See Also
remove, remove_copy, remove_copy_if