C++ multiset find()
C++ multiset 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 multiset i.e. multiset::end().
Syntax
Parameter
val: specifies the value to be searched in the multiset 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 multiset i.e. multiset::end().
Complexity
Logarithmic in size.
Iterator validity
No changes.
Data Races
The container is accessed (neither the constant nor the non-constant 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 multiset 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 find the key value e in the multiset m, if it is not found in the multiset then it will return a not found message otherwise, it will display the multiset.
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:
mymultiset contains: 10 20 30 50 70 80 90 100