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::find()
is a method available in the STL that searches the map and returns an iterator to the first occurrence of a specific key if found.
Syntax:
map_name.find( key );
Parameters: The multimap::find()
accepts a single parameter:
• key: Key to search for
Return value: An iterator to the element with the given key. multimap::end()
otherwise
Example of multimap::find() 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> ('a',4) ); cout<< "value to key 'a': " << m.find('a')->second; }
Output:
value to key 'a': 3