Javatpoint Logo
Javatpoint Logo

C++ multimap cend() function

The C++ multimap cend() function is used to return a constant 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

A const_iterator is an iterator that points to constant content.

Parameter

None

Return value

It returns a constant iterator which is pointing next to the last element of the multimap.

Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed.

Exception Safety

This member function never throws exceptions.

Example 1

Let's see the simple example for cend() function:

Output:

mymultimap contains: [a:Java] [a:Android] [b:C++] [b:Python]

In the above example, cend() function is used to return a const_ 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
100 = Deep
200 = Priya
200 = Aman
300 = Suman

In the above example, cend() function is used to return a const_iterator pointing next to the last element in the mymultimap multimap.

Example 4

Let's see a simple example:

Output:

Elements are:
10 + 10 = 20
10 + 30 = 40
20 + 20 = 40
end element (point next to the last): {3, 0}

In the above example, cend() function is used to return a const_iterator pointing next to the last element in the mymultimap multimap.

Next TopicC++ Multimap




Please Share

facebook twitter google plus pinterest