VOOZH about

URL: https://www.geeksforgeeks.org/cpp/map-find-function-in-c-stl/

⇱ map find() function in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

map find() function in C++ STL

Last Updated : 11 Jul, 2025

The std::map::find() is a built-in function in C++ STL that is used to find an element with given key in the map. It is a member function of std::map container so we can directly use it with any map.

Syntax

map_name.find(key)

Parameters

Return Value

  • If the key is found, it returns an iterator to the position where the key is present in the map.
  • If the key is not found, it returns an iterator to the end of the map.

Example of map::find()


Output
Key '2' found with value: 30
Key '5' not found!

Complexity Analysis of map::find()

std::map container in C++ is implemented using some Balanced Binary Search Tree (mostly R-B Tree). So,

  • Time Complexity: O(log n), where n is the number of elements.
  • Auxiliary Space: O(1)


Comment
Article Tags: