1: //set13.cpp 3: #include <iostream> 4: #include <set> 5: using namespace std; 7: int main() 8: { 9: cout << "\nThis program illustrates the lower_bound() member function " 10: "for sets. The lower\nbound of a value, in a sequence of values in " 11: "ascending order, is the value at\nthe first 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 lower = s.lower_bound(0); 27: if (lower == s.end()) 28: cout << "\nThe lower bound of 0 is at the end of the range."; 29: else 30: cout << "\nThe lower bound of 0 is " << *lower << "."; 32: lower = s.lower_bound(2); 33: if (lower == s.end()) 34: cout << "\nThe lower bound of 2 is at the end of the range."; 35: else 36: cout << "\nThe lower bound of 2 is " << *lower << "."; 38: lower = s.lower_bound(5); 39: if (lower == s.end()) 40: cout << "\nThe lower bound of 5 is at the end of the range."; 41: else 42: cout << "\nThe lower bound of 5 is " << *lower << "."; 44: lower = s.lower_bound(6); 45: if (lower == s.end()) 46: cout << "\nThe lower bound of 6 is at the end of the range."; 47: else 48: cout << "\nThe lower bound of 6 is " << *lower << "."; 50: lower = s.lower_bound(10); 51: if (lower == s.end()) 52: cout << "\nThe lower bound of 10 is at the end of the range."; 53: else 54: cout << "\nThe lower bound of 10 is " << *lower << "."; 56: lower = s.lower_bound(12); 57: if (lower == s.end()) 58: cout << "\nThe lower bound of 12 is at the end of the range."; 59: else 60: cout << "\nThe lower bound of 12 is " << *lower << "."; 61: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 62: }