multimap::find() method in C++ STL

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.


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


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;


value to key 'a': 3

This article is written by

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]