set::find() function in C++ STL

In C++, the standard library gives us the facility to use the Sets as a type of associative containers in which each element has to be unique. The set::find() is a C++ Standard Library function which is used to check whether the element is present in set or not. If element found it returns an iterator pointing to that element. If not found, it returns the position just after the last element in the set.


Set_Name.find( Element );

Parameter: The set::find() function accepts only single parameter:

  • Element: This parameter is the element to be searched in the set container.

Return value: The set::find() function returns the iterator pointing to that element, otherwise the position just after the last element in the set

Example of set::find() Function


#include <bits/stdc++.h> 
using namespace std; 
int main() 

    set<int> SET; 
    auto val = SET.find(4); 
    if (val != SET.end())
        cout << "Element Found"; 
        cout << "Element Not Found"; 
    return 0; 


Element Found

This article is written by

Pratik Singhal

Pratik Singhal

Please comment below, if you have any doubts or find any error in the above article.

Leave a Reply

Your email address will not be published. Required fields are marked *

[gravityforms id="5" description="false" titla="false" ajax="true"]