C++ set find()C++ set find() function is used to find an element with the given value val. If it finds the element then it returns an iterator pointing to the element otherwise, it returns an iterator pointing to the end of the set i.e. set::end(). SyntaxParameterval: specifies the value to be searched in the set container. Return valueIf it finds the element then it returns an iterator pointing to the element otherwise, it returns an iterator pointing to the end of the set i.e. set::end(). ComplexityLogarithmic in size. Iterator validityNo changes. Data RacesThe container is accessed (neither the const nor the non-const versions modify the container. No mapped values are accessed: concurrently accessing and modifying the elements is safe. Exception SafetyIf an exception is thrown, there are no changes in the container. Example 1Let's see the simple example to find the element with the given key value: Output: Iterator points to 300 Example 2Let's see a simple example to find the element: Output: Element not found In the above example, find() function finds the key value e in the set m, if it is not found in the set then it will return a not found message otherwise, it will display the set. Example 3Let's see a simple example: Output: Enter the element which you want to search: b b found and the value is b In the above example, find() function is used to find the element according to user's given value. Example 4Let's see a simple example: Output: myset contains: 10 20 30 50 70 80 90 100
Next TopicSet count() Function
|