1: //set08.cpp 3: #include <iostream> 4: #include <string> 5: #include <set> 6: using namespace std; 8: void DisplayNames 9: /**< 10: Displays all names in the set, one per line, and 11: then pauses to wait for the user to press Enter. 12: */ 13: ( 14: const set<string>& names //in 15: ); 18: int main() 19: { 20: cout << "\nThis program illustrates a const set iterator."; 21: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 23: cout << "\nFirst we create an array of name strings, and\nthen a set " 24: "of name strings from that array."; 25: string a[] = {"Tom", "Dick", "Harry", "Alice"}; 26: set<string> setOfNames(a, a+4); 27: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 29: DisplayNames(setOfNames); 30: } 32: void DisplayNames 33: ( 34: const set<string>& names //in 35: ) 36: { 37: //const input parameter requires const_iterator 38: set<string>::const_iterator p = names.begin(); 39: cout << "\nHere are the " << names.size() << " names in the set:\n"; 40: while (p != names.end()) cout << *p++ << endl; 41: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 42: }