1: //set14.cpp 3: #include <iostream> 4: #include <set> 5: using namespace std; 7: int main() 8: { 9: cout << "\nThis program illustrates the upper_bound() member function " 10: "for sets. The upper\nbound of a value, in a sequence of values in " 11: "ascending order, is the value at\nthe last location where the " 12: "given value could be inserted without destroying\nthe order of " 13: "the sequence. Equivalently, it is the first value in the sequence " 14: "\nthat is > the given value, if such a value exists; otherwise " 15: "it is the end of\nthe sequence, or the conceptual but non-" 16: "existent \"one-past-the-last\" value."; 17: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 19: int a[] ={2, 4, 6, 8, 10}; 20: set<int> s(a, a+5); 22: cout << "\nHere are the values in our set: "; 23: set<int>::iterator p = s.begin(); 24: while (p != s.end()) cout << *p++ << " "; 26: set<int>::iterator upper = s.upper_bound(0); 27: if (upper == s.end()) 28: cout << "\nThe upper bound of 0 is at the end of the range."; 29: else 30: cout << "\nThe upper bound of 0 is " << *upper << "."; 32: upper = s.upper_bound(2); 33: if (upper == s.end()) 34: cout << "\nThe upper bound of 2 is at the end of the range."; 35: else 36: cout << "\nThe upper bound of 2 is " << *upper << "."; 38: upper = s.upper_bound(5); 39: if (upper == s.end()) 40: cout << "\nThe upper bound of 5 is at the end of the range."; 41: else 42: cout << "\nThe upper bound of 5 is " << *upper << "."; 44: upper = s.upper_bound(6); 45: if (upper == s.end()) 46: cout << "\nThe upper bound of 6 is at the end of the range."; 47: else 48: cout << "\nThe upper bound of 6 is " << *upper << "."; 50: upper = s.upper_bound(10); 51: if (upper == s.end()) 52: cout << "\nThe upper bound of 10 is at the end of the range."; 53: else 54: cout << "\nThe upper bound of 10 is " << *upper << "."; 56: upper = s.upper_bound(12); 57: if (upper == s.end()) 58: cout << "\nThe upper bound of 12 is at the end of the range."; 59: else 60: cout << "\nThe upper bound of 12 is " << *upper << "."; 61: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 62: }