unordered_set find() function in C++ STL
The unordered_set::find() function is a built-in function in C++ STL which is used to search for an element in the container. It returns an iterator to the element, if found else, it returns an iterator pointing to unordered_set::end().
Syntax :
unordered_set_name.find(key)
Parameter: This function accepts a mandatory parameter key which specifies the element to be searched for.
Return Value: It returns an iterator to the element if found, else returns an iterator pointing to the end of unordered_set.
Below programs illustrate the unordered_set::find() function:
Program 1:
// C++ program to illustrate the // unordered_set::find() function #include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { unordered_set<string> sampleSet = { "geeks1", "for", "geeks2" }; // use of find() function if (sampleSet.find("geeks1") != sampleSet.end()) { cout << "element found." << endl; } else { cout << "element not found" << endl; } return 0; } |
element found.
Program 2:
// CPP program to illustrate the // unordered_set::find() function #include <iostream> #include <string> #include <unordered_set> using namespace std; int main() { unordered_set<string> sampleSet = { "geeks1", "for", "geeks2" }; // use of find() function if (sampleSet.find("geeksforgeeks") != sampleSet.end()) { cout << "found" << endl; } else { cout << "Not found" << endl; } return 0; } |
Not found
Recommended Posts:
- map find() function in C++ STL
- set find() function in C++ STL
- unordered_multiset find() function in C++STL
- unordered_multimap find() function in C++ STL
- 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++
- fma() function in C++
- exp() function C++
- log() function in C++
- div() function in C++
- lldiv() function in C++ STL
- set equal_range() function in C++ STL
- set insert() function in C++ STL
- set upper_bound() function in C++ STL
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.



