Skip to content
Related Articles

Related Articles

Improve Article
multimap rbegin in C++ STL
  • Last Updated : 18 Oct, 2018

multimap::rbegin() is a built-in-function in C++ STL which returns an iterator pointing to the last element of the container.
Syntax:

multimap_name.rbegiin()

Parameters: The function does not take any parameter.
Return Value: The function returns a reverse iterator pointing to the last element of the container.
(Note: Reverse iterators iterate backwards i.e when they are increased they move towards the beginning of the container)

The following two programs illustrates the function.

Program 1




// CPP program to illustrate
// multimap::rbegin()
  
#include <iostream>
#include <map>
using namespace std;
  
int main()
{
    multimap<char, int> sample;
  
    // Insert pairs in the multimap
    sample.insert(make_pair('a', 10));
    sample.insert(make_pair('b', 20));
    sample.insert(make_pair('b', 30));
    sample.insert(make_pair('c', 40));
    sample.insert(make_pair('c', 50));
  
    // Get the last element by
    // multimap::rbegin()
    cout << sample.rbegin()->first << " = " << sample.rbegin()->second;
}

Output

c = 50

Program 2




// CPP program to illustrate
// multimap::rbegin()
  
#include <iostream>
#include <map>
using namespace std;
  
int main()
{
    multimap<char, int> sample;
  
    // Insert pairs in the multimap
    sample.insert(make_pair('a', 10));
    sample.insert(make_pair('b', 20));
    sample.insert(make_pair('b', 30));
    sample.insert(make_pair('c', 40));
    sample.insert(make_pair('c', 50));
  
    // Show content of the multimap
    for (auto it = sample.rbegin(); it != sample.rend(); it++)
        cout << it->first << " = " << it->second << endl;
}

Output

c = 50
c = 40
b = 30
b = 20
a = 10
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :