1: //set_symmetric_difference1a.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: "set_symmetric_difference()\nalgorithm (default version) " 12: "to find the values that are in a first vector\nof integers " 13: "but not in a second vector of integers, as well as those " 14: "integers\nthat are in the second vector but not in the first, " 15: "and write them out to a\nthird vector of integers."; 16: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 18: int a1[] = {11, 12, 12, 12, 12, 13, 14, 15}; 19: vector<int> v1(a1, a1+8); 21: cout << "\nHere are the values in the vector v1:\n"; 22: for (vector<int>::size_type i=0; i<v1.size(); i++) 23: cout << v1.at(i) << " "; 24: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 26: int a2[] = {11, 12, 12, 13, 13, 16, 17, 18}; 27: vector<int> v2(a2, a2+8); 29: cout << "\nHere are the values in the vector v2:\n"; 30: for (vector<int>::size_type i=0; i<v2.size(); i++) 31: cout << v2.at(i) << " "; 32: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 34: int a3[] = {101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 35: 111, 112, 113, 114, 115}; 36: vector<int> v3(a3, a3+15); 38: cout << "\nHere are the values in the vector v3:\n"; 39: for (vector<int>::size_type i=0; i<v3.size(); i++) 40: cout << v3.at(i) << " "; 41: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 43: cout << "\nNow we find the values that are in v1 but not in v2, " 44: "as well as those that are\nin v2 but not in v1, and write " 45: "them out to v3, starting at the beginning of v3."; 46: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 48: vector<int>::iterator p; 49: p = set_symmetric_difference(v1.begin(), v1.end(), 50: v2.begin(), v2.end(), v3.begin()); 52: cout << "\nHere are the revised contents of v3:\n"; 53: for (vector<int>::size_type i=0; i<v3.size(); i++) 54: cout << v3.at(i) << " "; 55: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 57: cout << "\nThe iterator returned by the algorithm is pointing at " 58: "the value " << *p << "."; 59: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 60: }