Multimaps are associative containers available in the C++ Standard Library. They are similar to a map with an addition that multiple elements can have the same keys. The multimap::lower_bound()
is a method available in the STL that returns an iterator pointing to the first element in the multimap whose key is not considered to go before the specified key.
Syntax:
map_name.lower_bound( val );
Parameters: The multimap::lower_bound()
accepts a single parameter:
• val: Key to search for
Return value: An iterator to the element whose key is not before val. multimap::end()
otherwise
Example of multimap::lower_bound() method
#include<iostream> #include<map> using namespace std; int main() { multimap<char,int> m; m.insert( pair<int,int> ('c',1) ); m.insert( pair<int,int> ('b',2) ); m.insert( pair<int,int> ('a',3) ); m.insert( pair<int,int> ('d',9) ); m.insert( pair<int,int> ('d',7) ); m.insert( pair<int,int> ('d',4) ); cout<< "lower bound value of key 'd' is: " << m.lower_bound('d')->second; }
Output:
lower bound value of key 'd' is: 9