Javatpoint Logo
Javatpoint Logo

C++ multimap end() function

The C++ multimap end() function is used to return an iterator which is next to the last entry in the multimap.

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 multimap.

Complexity

Constant.

Iterator validity

No changes.

Data Races

The container is accessed neither the const nor the non-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:

a => Java
a => Android
b => C++
b => Python

In the above example, end() function is used to return an iterator pointing next to the last element in the mymultimap multimap.

Example 2

Let's see a simple example to iterate over the multimap using for-each loop:

Output:

Room1 = 100
Room1 = 300
Room1 = 100
Room2 = 200

In the above example, we are using an STL algorithm std::for-each to iterate over the multimap. It will iterate on each of the multimap element and call the callback provided by us.

Example 3

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

Output:

100 = Nikita
200 = Deep
200 = Priya
300 = Aman
400 = Suman

In the above example, end() function is used to return an iterator pointing next to the last element in the mymultimap multimap.

Example 4

Let's see a simple example:

Output:

Elements are:
10 * 10 = 100
10 * 30 = 300
20 * 20 = 400
20 * 10 = 200

In the above example, end() function is used to return an iterator pointing next to the last element in the mymultimap multimap.

Next TopicC++ Multimap




Help Others, Please Share

facebook twitter pinterest