unordered_multimap find() function in C++ STL
The unordered_multimap::find() is a built-in function in C++ STL which returns an iterator which points to one of the elements which has the key k. If the container does not contain any element with key k, then it returns an iterator which points to the position which is past the last element in the container.
Syntax:
unordered_multimap_name.find(k)
Parameters: The function accepts a mandatory parameter k which specifies the key.
Return Value: It returns an iterator which points to the position where an element with key k is.
Below programs illustrate the above function:
Program 1:
// C++ program to illustrate the // unordered_multimap::find() function #include <iostream> #include <unordered_map> using namespace std; int main() { // declaration unordered_multimap<int, int> sample; // inserts key and element sample.insert({ 1, 2 }); sample.insert({ 1, 2 }); sample.insert({ 2, 3 }); sample.insert({ 3, 4 }); sample.insert({ 2, 6 }); // find the element with key 1 and print auto it = sample.find(1); if (it != sample.end()) cout << 1 << ":" << it->second << endl; else cout << "element with key 1 not found\n"; // find the element with // key 2 and print it = sample.find(2); if (it != sample.end()) cout << 2 << ":" << it->second << endl; else cout << "element with key 2 not found\n"; // find the element with // key 100 and print it = sample.find(100); if (it != sample.end()) cout << 100 << ":" << it->second << endl; else cout << "element with key 100 not found\n"; return 0; } |
1:2 2:6 element with key 100 not found
Program 2:
// C++ program to illustrate the // unordered_multimap::find() #include <iostream> #include <unordered_map> using namespace std; int main() { // declaration unordered_multimap<char, char> sample; // inserts element sample.insert({ 'a', 'b' }); sample.insert({ 'a', 'b' }); sample.insert({ 'a', 'd' }); sample.insert({ 'b', 'e' }); sample.insert({ 'b', 'd' }); // find the element with // key r and print auto it = sample.find('r'); if (it != sample.end()) cout << "r" << ":" << it->second << endl; else cout << "element with key r not found\n"; // find the element with // key a and print it = sample.find('a'); if (it != sample.end()) cout << 'a' << ":" << it->second << endl; else cout << "element with key a not found\n"; // find the element with // key 'b' and print it = sample.find('b'); if (it != sample.end()) cout << "b" << ":" << it->second << endl; else cout << "element with key b not found\n"; return 0; } |
element with key r not found a:d b:d
Recommended Posts:
- set find() function in C++ STL
- map find() function in C++ STL
- unordered_set find() function in C++ STL
- multiset find() function in C++ STL
- unordered_multiset find() function in C++STL
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- std::find in C++
- fma() function in C++
- div() function in C++
- exp() function C++
- log() function in C++
- string find in C++
- unordered_map find in C++ STL
- Find if there is a subarray with 0 sum
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



