#include#include int main() { std::set myset = { 1, 2, 4, 6, 8, 11 }; auto it = myset.lower_bound(5); std::cout << "The first element not less than 5 is " << *it << std::endl; return 0; }
The first element not less than 5 is 6
#include#include int main() { std::set myset = { 1, 2, 4, 6, 8, 11 }; auto it = myset.lower_bound(13); if(it == myset.end()) std::cout << "Value greater than all elements in set" << std::endl; else std::cout << "The first element not less than 13 is " << *it << std::endl; return 0; }
Value greater than all elements in setIn the above code, we try to find the first element not less than 13. Since 13 is greater than all the elements in the set, it returns end() iterator. We check if the returned iterator is equal to end() to check if the value was greater than all elements in the set. The `std::set::lower_bound()` function is part of the C++ Standard Library.