Or login with:
#include <algorithm> template < class InputIterator, class OutputIterator, class Type > OutputIterator remove_copy( InputIterator first, InputIterator last, OutputIterator result, const Type& val );Parameters:
| Parameter | Description |
|---|---|
| first | An input iterator addressing the position of the first element in the range from which elements are being removed |
| last | An input iterator addressing the position one past the final element in the range from which elements are being removed |
| result | An output iterator addressing the position of the first element in the destination range to which elements are being removed |
| val | The value that is to be removed from the range |
val from the range [first, last) to result.last - first comparisons for equality and last - first assignments.#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a1[] = {1, 2, 2, 3, 4, 5, 2, 3, 6, 7, 2, 8, 3, 9, 10, 2}; vector<int> v1(a1, a1+16); cout <<"\nHere are the sixteen values in v1:\n"; for (vector<int>::size_type i=0; i<v1.size(); i++) cout <<v1.at(i)<<" "; int a2[] = {101, 102, 103, 104, 105, 106, 107, 108,109, 110, 111, 112, 113, 114, 115, 116}; vector<int> v2(a2, a2+16); cout <<"\nHere are the sixteen values in v2:\n"; for (vector<int>::size_type i=0; i<v2.size(); i++) cout <<v2.at(i)<<" "; cout <<"\nNow we copy all values except 2 from v1 to v2," " starting at the 3rd value of v2."; vector<int>::iterator p = remove_copy(v1.begin(), v1.end(), v2.begin()+2, 2); cout <<"\nHere are the revised values in v2:\n"; for (vector<int>::size_type i=0; i<v2.size(); i++) cout <<v2.at(i)<<" "; cout <<"\nThe iterator returned by the algorithm is pointing at the value" <<*p<<"."; return 0; }
You must login to leave a messge