Multimaps are associative containers available in the C++ Standard Library. They are similar to a map with an addition that multiple elements can have the same keys. The multimap::rend()
is a method available in the STL that returns a reverse iterator pointing to imaginary element the precedes the first element in the container.
Syntax:
map_name.rend()
Parameters: The multimap::rend()
does not accept any parameter:
Return value: Reverse iterator to the imaginary element before the first element in the container.
Example of multimap::rend() method
#include<iostream> #include<map> using namespace std; int main() { multimap<char,int> m; m.insert( pair<int,int> ('a',1) ); m.insert( pair<int,int> ('b',2) ); m.insert( pair<int,int> ('c',3) ); m.insert( pair<int,int> ('d',4) ); multimap<char, int>::reverse_iterator it; for( it = m.rbegin(); it != m.rend(); ++it) { cout<< it->first << " : "<< it->second<<endl; } }
Output:
d : 4 c : 3 b : 2 a : 1