Javatpoint Logo
Javatpoint Logo

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().

Syntax

Parameter

val: specifies the value to be searched in the set container.

Return value

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().

Complexity

Logarithmic in size.

Iterator validity

No changes.

Data Races

The 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 Safety

If an exception is thrown, there are no changes in the container.

Example 1

Let's see the simple example to find the element with the given key value:

Output:

Iterator points to 300

Example 2

Let'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 3

Let'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 4

Let's see a simple example:

Output:

myset contains: 10 20 30 50 70 80 90 100






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA