Javatpoint Logo
Javatpoint Logo

C++ multiset begin()

C++ multiset begin() function is used to return an iterator referring to the first element of the multiset container.

Syntax

Parameter

None

Return value

It returns an iterator pointing to the first element of the multiset.

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 mymultiset are: 
C++
C++
Java
SQL

In the above example, begin() function is used to return an iterator pointing to the first element in the mymultiset multiset.

Example 2

Let's see a simple example:

Output:

0 2 2 4 5 5

Example 3

Let's see a simple example to iterate over the multiset using while loop:

Output:

Elements of mymultiset are: 
Aman
Deep
Nikita
Nikita
Priya
Suman

In the above example, begin() function is used to return an iterator pointing to the first element in the mymultiset multiset.

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 mymultiset multiset.

Next TopicC++ multiset




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials