Source of includes1a.cpp


  1: //includes1a.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 includes() "
 11:         "algorithm (default\nversion) to test whether the values in a "
 12:         "second (sorted) range of integer\nvalues in a vector of integers "
 13:         "are all present in a first (sorted) range\nof integer values, "
 14:         "also in a vector of integers.";
 15:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 17:     int a1[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
 18:     vector<int> v1(a1, a1+10);

 20:     cout << "\nHere are the contents of v1:\n";
 21:     for (vector<int>::size_type i=0; i<v1.size(); i++)
 22:         cout << v1.at(i) << " ";
 23:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 25:     int a2[] = {2, 16, 128, 512};
 26:     vector<int> v2(a2, a2+4);

 28:     cout << "\nHere are the contents of v2:\n";
 29:     for (vector<int>::size_type i=0; i<v2.size(); i++)
 30:         cout << v2.at(i) << " ";
 31:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 33:     if (includes(v1.begin(), v1.end(), v2.begin(), v2.end()))
 34:         cout << "\nv1 includes v2.";
 35:     else
 36:         cout << "\nv1 does not include v2.";
 37:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 39:     int a3[] = {2, 16, 128, 1024};
 40:     vector<int> v3(a3, a3+4);

 42:     cout << "\nHere are the contents of v3:\n";
 43:     for (vector<int>::size_type i=0; i<v3.size(); i++)
 44:         cout << v3.at(i) << " ";
 45:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 47:     if (includes(v1.begin(), v1.end(), v3.begin(), v3.end()))
 48:         cout << "\nv1 includes v3.";
 49:     else
 50:         cout << "\nv1 does not include v3.";
 51:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 52: }