home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / STL / Slides / STL4.cp < prev    next >
Encoding:
Text File  |  1998-06-15  |  975 b   |  41 lines  |  [TEXT/CWIE]

  1. // STL4.cp
  2. #include <iostream>
  3. #include <set>
  4. using namespace std;
  5. int main()
  6. {
  7.     typedef    set<char> MySet;
  8.     typedef    multiset<char> MyMultiSet;
  9.     ostream_iterator<char>    out(cout);
  10.     char    start[] = "sleep is a poor substitute for caffeine";
  11.     MySet    s(start, start + strlen(start));
  12.     MyMultiSet    ms;
  13.     ms.insert(start, start + strlen(start));
  14.  
  15.     cout << "      start: ";
  16.     copy(s.begin(), s.end(), out);
  17.     cout << "\n      start: ";
  18.     copy(ms.begin(), ms.end(), out);
  19.  
  20.     MySet::iterator    si1, si2;
  21.     MyMultiSet::iterator    msi1, msi2;
  22.     si1 = s.lower_bound('b');
  23.     si2 = s.upper_bound('s');
  24.     s.erase(' ');
  25.     s.erase(si1, si2);
  26.     msi1 = ms.lower_bound('b');
  27.     msi2 = ms.upper_bound('s');
  28.     ms.erase(' ');
  29.     ms.erase(msi1, msi2);
  30.  
  31.     cout << "\nremoved b-s: ";
  32.     copy(s.begin(), s.end(), out);
  33.     cout << "\nremoved b-s: ";
  34.     copy(ms.begin(), ms.end(), out);
  35.     cout << "\n";
  36. }
  37. //       start:  abcefilnoprstu
  38. //       start:       aabceeeeefffiiilnooopprrsssstttuu
  39. // removed b-s: atu
  40. // removed b-s: aatttuu
  41.