unordered_set find() function in C++ STL Last Updated : 08 Nov, 2023 Comments Improve Suggest changes 21 Likes Like Report 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: CPP // 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; } Outputelement found. Time Complexity: O(1) Auxiliary Space: O(n) Program 2: CPP // 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; } OutputNot found Time Complexity: O(1) Auxiliary Space: O(n) Create Quiz Comment B barykrg Follow 21 Improve B barykrg Follow 21 Improve Article Tags : Misc C++ CPP-Functions cpp-unordered_set cpp-unordered_set-functions +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like