#includeusing namespace std; int main() { map m; m.insert({ 1, 10 }); m.insert({ 2, 20 }); m.insert({ 3, 30 }); m.insert({ 4, 40 }); m.insert({ 5, 50 }); auto it = m.upper_bound(3); cout << "The key " << it->first << " maps to value " << it->second << endl; return 0; }
#includeThis code snippet creates a map `m` and inserts some key-value pairs. It then finds the `upper_bound` of key `"John"` in the map `m` using the `upper_bound` function and stores the iterator to the next greater element than `"John"` in the map in `it`. It then prints the key-value pair pointed to by `it`. The `upper_bound` function is a part of the standard library of C++. Therefore, no external package library is required for its usage.using namespace std; int main() { map m; m.insert({ "John", 50 }); m.insert({ "Alex", 30 }); m.insert({ "Mike", 20 }); m.insert({ "David", 40 }); m.insert({ "Ryan", 60 }); auto it = m.upper_bound("John"); cout << "The key " << it->first << " maps to value " << it->second << endl; return 0; }