C++ set end()
C++ set end() function is used to return an iterator which is next to the last entry in the set.
Note:- This is a placeholder. No element exists in this location and attempting to access is undefined behavior.
Syntax
Parameter
None
Return value
It returns an iterator which is pointing next to the last element of the set.
Complexity
Constant.
Iterator validity
No changes.
Data Races
Concurrently accessing the elements of a set is safe.
The container is accessed neither the non-const nor the const versions modify the container.
Exception Safety
This member function never throws exception.
Example 1
Let’s see the simple example for end() function:
Output:
C++ Java SQL
In the above example, end() function is used to return an iterator pointing next to the last element in the myset set.
Example 2
Let’s see a simple example to iterate over the set using for-each loop:
Output:
0 1 2 4 5 9
Example 3
Let’s see a simple example to iterate over the set using while loop:
Output:
Elements of myset are: Aman Deep Nikita Priya Suman
In the above example, end() function is used to return an iterator pointing next to the last element in the myset set.
Example 4
Let’s see a simple example:
Output:
Enter value to find: 60 Element not found. Enter value to find: 30 Element found: 30
In the above example, end() function is used to return an iterator pointing next to the last element in the myset set.