C++ set begin()
C++ set begin() function is used to return an iterator referring to the first element of the set container.
Syntax
Parameter
None
Return value
It returns an iterator pointing to the first element of the set.
Complexity
Constant.
Iterator validity
No changes.
Data Races
The container is accessed. Neither the constant nor the non-constant versions modify the container.
Exception Safety
This function never throws exceptions.
Example 1
Let’s see the simple example for begin() function:
Output:
Contents of myset are: C++ Java SQL
In the above example, begin() function is used to return an iterator pointing to the first element in the myset set.
Example 2
Let’s see a simple example:
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, begin() function is used to return an iterator pointing to the first element in the myset set.
Example 4
Let’s see a simple example:
Output:
The first element of s1 is 1 The first element of s1 is now 2
In the above example, begin() function is used to return an iterator pointing to the first element in the myset set.