1: //set07.cpp
3: #include <iostream>
4: #include <set>
5: using namespace std;
7: int main()
8: {
9: cout << "\nThis program illustrates reverse iterators for sets, as "
10: "well as\nthe member functions rbegin() and rend().";
11: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
13: cout << "\nFirst we create an array of five characters, then a set "
14: "\nof the same five characters from that array.";
15: char a[] = {'A', 'B', 'C', 'D' ,'E'};
16: set<char> s(a, a+5);
17: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
19: cout << "\nNow we use a reverse iterator to display the set "
20: "contents\nin descending key order.";
21: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
23: cout << endl;
24: set<char>::reverse_iterator r_p = s.rbegin();
25: while (r_p != s.rend()) cout << *r_p++ << " ";
26: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
28: cout << "\nFinally, we use a reverse iterator to display the set "
29: "contents\nin ascending key order.";
30: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
31: r_p = s.rend();
32: cout << endl;
33: while (r_p != s.rbegin())
34: {
35: --r_p;
36: cout << *r_p << " ";
37: }
38: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
39: }