multimap::begin() method in C++ STL

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::begin() is a method available in the STL that returns an iterator pointing to the first element in the container.

Syntax:

map_name.begin();

Parameters: The multimap::begin() does not accept any parameter:
Return value: Iterator to first element in the container.

Example of multimap::begin() 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) );


    cout<< "First element of multimap is: \n";
    cout<< m.begin()->first <<" : "<< m.begin()->second;
}

Output:

First element of multimap is:
a : 1

This article is written by

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top