std::mapmy_map; my_map[1] = "one"; my_map[2] = "two"; my_map[4] = "four"; auto it = my_map.lower_bound(3); std::cout << it->second << std::endl; // prints "four"
std::mapIn this example, we create a map with character keys and integer values. We insert three elements into the map with keys 'a', 'b', and 'c'. We then call the lower_bound function with the key value of 'd', which returns an iterator pointing to the end of the map since there is no element with a key greater than or equal to 'd'. We then check if the returned iterator is equal to the end iterator, and if so print out a message indicating that no element was found in the map. Package/library: STL (Standard Template Library)my_map; my_map['a'] = 1; my_map['b'] = 2; my_map['c'] = 3; auto it = my_map.lower_bound('d'); if (it == my_map.end()) { std::cout << "No element with key >= 'd' found in map\n"; }