unordered_multimap begin() and end() function in C++ STL
- The unordered_multimap::begin() is a built-in function in C++ STL which returns an iterator pointing to the first element in the container or to the first element in one of its bucket.
Syntax:
unordered_multimap_name.begin(n)
Parameters: The function accepts one parameter. If a parameter is passed, it returns an iterator pointing to the first element in the bucket. If no parameter is passed, then it returns a constant iterator pointing to the first element in the unordered_multimap container.
Return Value: It returns an iterator. It cannot be used to change the value of the unordered_multimap element.
Below programs illustrates the above function:
Program 1:
// C++ program to illustrate the// unordered_multimap::begin() function#include <bits/stdc++.h>usingnamespacestd;intmain(){// declarationunordered_multimap<int,int> sample;// inserts elementsample.insert({ 1, 2 });sample.insert({ 3, 4 });sample.insert({ 3, 4 });sample.insert({ 2, 3 });sample.insert({ 2, 3 });// prints all elementcout <<"Key and Elements: \n";for(autoit = sample.begin(); it != sample.end(); it++)cout <<" "<< it->first <<"\t "<< it->second << endl;autoit = sample.begin();// print the first elementcout <<"\nThe first key and element: "<< it->first <<" ";cout << it->second;return0;}chevron_rightfilter_noneOutput:Key and Elements: 2 3 2 3 1 2 3 4 3 4 The first key and element: 2 3
Program 2:
// C++ program to illustrate the// unordered_multimap::begin(bucket) function#include <bits/stdc++.h>usingnamespacestd;intmain(){// declarationunordered_multimap<int,int> sample;// inserts elementsample.insert({ 1, 2 });sample.insert({ 3, 4 });sample.insert({ 3, 4 });sample.insert({ 2, 3 });sample.insert({ 2, 3 });// prints all elementcout <<"Key and Elements of first bucket: \n";for(autoit = sample.begin(1); it != sample.end(1); it++)cout <<" "<< it->first <<"\t "<< it->second << endl;autoit = sample.begin(1);// print the first elementcout <<"\nThe first key and element in first bucket: "<< it->first <<" ";cout << it->second;return0;}chevron_rightfilter_noneOutput:Key and Elements of first bucket: 1 2 The first key and element in first bucket: 1 2
- The unordered_multimap::end() is a built-in function in C++ STL which returns an iterator pointing to the position after the last element in the container or to the position after the last element in one of its bucket.
Syntax:
unordered_multimap_name.end(n)
Parameters: The function accepts one parameter. If a parameter is passed, it returns an iterator pointing to the position after the last element in one of its bucket. If no parameter is passed, then it returns an iterator pointing to the position after the last element in the unordered_multimap container.
Return Value: It returns an iterator. It cannot be used to change the value of the unordered_multimap element.
Below programs illustrates the above function:
Program 1:
// C++ program to illustrate the// unordered_multimap::end() function#include <bits/stdc++.h>usingnamespacestd;intmain(){// declarationunordered_multimap<int,int> sample;// inserts elementsample.insert({ 1, 2 });sample.insert({ 3, 4 });sample.insert({ 3, 4 });sample.insert({ 2, 3 });sample.insert({ 2, 3 });// prints all elementcout <<"Key and Elements: \n";for(autoit = sample.begin(); it != sample.end(); it++)cout <<" "<< it->first <<"\t "<< it->second << endl;return0;}chevron_rightfilter_noneOutput:Key and Elements: 2 3 2 3 1 2 3 4 3 4
Program 2:
// C++ program to illustrate the// unordered_multimap::end(bucket) function#include <bits/stdc++.h>usingnamespacestd;intmain(){// declarationunordered_multimap<int,int> sample;// inserts elementsample.insert({ 1, 2 });sample.insert({ 3, 4 });sample.insert({ 3, 4 });sample.insert({ 2, 3 });sample.insert({ 2, 3 });// prints all elementcout <<"Key and Elements of first bucket: \n";for(autoit = sample.begin(1); it != sample.end(1); it++)cout <<" "<< it->first <<"\t "<< it->second << endl;return0;}chevron_rightfilter_noneOutput:Key and Elements of first bucket: 1 2
Recommended Posts:
- multiset begin() and end() function in C++ STL
- unordered_set begin() function in C++ STL
- valarray begin() function in C++
- match_results begin() and end() function in C++ STL
- unordered_multiset begin() function in C++ STL
- set::begin() and set::end() in C++ STL
- map::begin() and end() in C++ STL
- unordered_map begin() in C++
- deque::begin() and deque::end in C++ STL
- list::begin() and list::end() in C++ STL
- multimap::begin() and multimap::end() in C++ STL
- vector::begin() and vector::end() in C++ STL
- array::begin() and array::end() in C++ STL
- forward_list::begin() and forward_list::end() in C++ STL
- Function Overloading vs Function Overriding in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



