Open In App

set find() Function in C++ STL

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
46 Likes
Like
Report

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

Syntax

 set_name.find(key) 

Parameters

  • key: The element which we have to find.

Return Value

  • If the element is found, it returns an iterator to its position in the set.
  • If the element is not found, then it returns the iterator to the end.

Finding elements in a set is straightforward with the find() function.

Example of set::find()


Output
Key '3' found
Key '1' not found!

Complexity Analysis of set::find()

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



Article Tags :
Practice Tags :

Similar Reads