multimap::find() is a built-in function in C++ STL which returns an iterator or a constant iterator that refers to the position where the key is present in the multimap. In case of multiple same keys being present, the iterator that refers to one of the keys (typically the first one). In case we wish to get all the items with a given key, we may use equal_range(). If the key is not present in the multimap container, it returns an iterator or a constant iterator which refers to multimap.end().
Syntax:
iterator multimap_name.find(key)
or
constant iterator multimap_name.find(key)
Parameters: The function accepts one mandatory parameter key which specifies the key to be searched in the multimap container.
Return Value: The function returns an iterator or a constant iterator which refers to the position where the key is present in the multimap. If the key is not present in the multimap container, it returns an iterator or a constant iterator which refers to multimap.end().
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
multimap< int , int > mp;
mp.insert({ 2, 30 });
mp.insert({ 1, 40 });
mp.insert({ 2, 60 });
mp.insert({ 3, 20 });
mp.insert({ 1, 50 });
mp.insert({ 4, 50 });
cout << "The elements from position 3 in multimap are : \n" ;
cout << "KEY\tELEMENT\n" ;
for ( auto itr = mp.find(3); itr != mp.end(); itr++)
cout << itr->first
<< '\t' << itr->second << '\n' ;
return 0;
}
|
Output:
The elements from position 3 in multimap are :
KEY ELEMENT
3 20
4 50
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
01 Jul, 2021
Like Article
Save Article