Source of set01.cpp


  1: //set01.cpp

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

  7: int main()
  8: {
  9:     cout << "\nThis program creates a set from an array of integer "
 10:         "values and\nthen displays the values in the set using a set "
 11:         "iterator.";
 12:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

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

 20:     cout << "\nHowever, the size of the set is " << s.size() << ".";
 21:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 23:     cout << "\nHere are the values in the set:\n";
 24:     set<int>::iterator p = s.begin();
 25:     while (p != s.end()) cout  << *p++ << " ";
 26:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 27: }