1: //remove_copy1a.cpp
3: #include <iostream>
4: #include <vector>
5: #include <algorithm>
6: using namespace std;
8: int main()
9: {
10: cout << "\nThis program illustrates the use of the STL "
11: "remove_copy() algorithm to copy\nall values except a "
12: "particular value from one vector of integers to another.";
13: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
15: int a1[] = {1, 2, 2, 3, 4, 5, 2, 3, 6, 7, 2, 8, 3, 9, 10, 2};
16: vector<int> v1(a1, a1+16);
18: cout << "\nHere are the sixteen values in v1:\n";
19: for (vector<int>::size_type i=0; i<v1.size(); i++)
20: cout << v1.at(i) << " ";
21: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
23: int a2[] = {101, 102, 103, 104, 105, 106, 107, 108,
24: 109, 110, 111, 112, 113, 114, 115, 116};
25: vector<int> v2(a2, a2+16);
27: cout << "\nHere are the sixteen values in v2:\n";
28: for (vector<int>::size_type i=0; i<v2.size(); i++)
29: cout << v2.at(i) << " ";
30: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
32: cout << "\nNow we copy all values except 2 from v1 to v2, starting "
33: "at the 3rd value of v2.";
34: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
36: vector<int>::iterator p = remove_copy(v1.begin(), v1.end(),
37: v2.begin()+2, 2);
39: cout << "\nHere are the revised values in v2:\n";
40: for (vector<int>::size_type i=0; i<v2.size(); i++)
41: cout << v2.at(i) << " ";
42: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
44: cout << "\nThe iterator returned by the algorithm is pointing at "
45: "the value " << *p << ".";
46: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
47: }