1: //set_union1a.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 set_union() " 11: "algorithm (default\nversion) to find the values that are in a " 12: "first vector of integers or in a\nsecond vector of integers (or " 13: "in both), and write them out to a third vector\nof integers."; 14: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 16: int a1[] = {11, 12, 12, 12, 12, 13, 14, 15}; 17: vector<int> v1(a1, a1+8); 19: cout << "\nHere are the values in the vector v1:\n"; 20: for (vector<int>::size_type i=0; i<v1.size(); i++) 21: cout << v1.at(i) << " "; 22: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 24: int a2[] = {11, 12, 12, 13, 13, 16, 17, 18}; 25: vector<int> v2(a2, a2+8); 27: cout << "\nHere are the values in the vector 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: int a3[] = {101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 33: 111, 112, 113, 114, 115}; 34: vector<int> v3(a3, a3+15); 36: cout << "\nHere are the values in the vector v3:\n"; 37: for (vector<int>::size_type i=0; i<v3.size(); i++) 38: cout << v3.at(i) << " "; 39: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 41: cout << "\nNow we find the values that are in v1 or in v2, " 42: "or in both,\nand write them out to v3, starting at the " 43: "beginning of v3."; 44: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 46: vector<int>::iterator p; 47: p = set_union(v1.begin(), v1.end(), 48: v2.begin(), v2.end(), v3.begin()); 50: cout << "\nHere are the revised contents of v3:\n"; 51: for (vector<int>::size_type i=0; i<v3.size(); i++) 52: cout << v3.at(i) << " "; 53: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 55: cout << "\nThe iterator returned by the algorithm is pointing at " 56: "the value " << *p << "."; 57: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 58: }