Source of set04.cpp


  1: //set04.cpp

  3: #include <iostream>
  4: #include <set>
  5: #include <functional>
  6: using namespace std;

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates how to use a built-in function "
 11:         "object\nto alter the sort order from the default used by the "
 12:         "set class.";
 13:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 15:     cout << "\nWe begin by creating an array of 10 positive integers, "
 16:         "and\nthen we create a set containing the same values.";
 17:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 18:     int a[] = {7, 4, 9, 1, 3, 8, 2, 5, 6, 10};
 19:     set<int, greater<int>> s1(a, a+10);

 21:     cout << "\nHere are the values in the set, and note their order:\n";
 22:     set<int, greater<int>>::iterator p = s1.begin();
 23:     while (p != s1.end()) cout  << *p++ << " ";
 24:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 25: }