Skip to content
Related Articles

Related Articles

unordered_map find in C++ STL

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 24 Dec, 2018

find function in C++ is used to search for a specific key in an unordered map.



Parameters: It takes the key as a parameter.

Return values: If the given key exists in unordered_map it returns an iterator to that element otherwise it returns the end of the map iterator.

Below program illustrate the working of find function:

// CPP program to demonstrate implementation of
// find function in unordered_map.
#include <bits/stdc++.h>
using namespace std;
int main()
    unordered_map<int, bool> um;
    um[12] = true;
    um[6789] = false;
    um[456] = true;
    // Searching for element 23
    if (um.find(23) == um.end())
        cout << "Element Not Present\n";
        cout << "Element Present\n";
    // Searching for element 12
    if (um.find(12) == um.end())
        cout << "Element Not Present\n";
        cout << "Element Present\n";
    return 0;


Element Not Present
Element Present

Time Complexity : O(1) on average.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!