C++ set cbegin()
C++ set cbegin() function is used to return a constant iterator pointing to the first element of the set container.
Syntax
A const_iterator is an iterator that points to constant content.
Parameter
None
Return value
It returns a const_iterator pointing to the first element of the set.
Complexity
Constant
Iterator validity
No changes.
Data Races
The container is accessed.
Concurrently accessing the elements of a set is safe.
Exception Safety
This member function never throws exception.
Example 1
Let’s see the simple example for cbegin() function:
Output:
C++ Java SQL
In the above example, cbegin() function is used to return a constant iterator pointing to the first element in the myset set.
Example 2
Let’s see a simple example:
Output:
The first element of s1 is 1 The first element of s1 is now 2
Example 3
Let’s see a simple example to iterate over the set using while loop:
Output:
Dolly John Nikita Robin
In the above example, cbegin() function is used to return an iterator pointing to the first element in the myset set.
Example 4
Let’s see another simple example:
Output:
Increasing order: ______________________ 290 350 400 410 465 Smallest Number is: 290 Biggest Number is: 465
In the above example, cbegin() function is used to return an iterator pointing to the first element in the myset set.