- The multiset::begin() is a built-in function in C++ STL which returns an iterator pointing to the first element in the multiset container. Since multiset always contains elements in an ordered way, begin() always points to the first element according to the sorting criterion.
Syntax:
iterator multiset_name.begin()
Parameters: The function does not accept any parameters.
Return value: The function returns an iterator pointing to the first element in the container.
Below program illustrate the above-mentioned function:
// CPP program to demonstrate the// multiset::begin() function#include <bits/stdc++.h>usingnamespacestd;intmain(){intarr[] = { 14, 10, 15, 11, 10 };// initializes the set from an arraymultiset<int> s(arr, arr + 5);// Print the first elementcout <<"The first element is: "<< *(s.begin()) << endl;// prints all elements in setfor(autoit = s.begin(); it != s.end(); it++)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:
The first element is: 10 10 10 11 14 15
- The multiset::end() is a built-in function in C++ STL which returns an iterator pointing to the position past the last element in the container.
Syntax:iterator multiset_name.end()
Parameters: The function does not accept any parameters.
Return value: The function returns an iterator pointing to the position past the last element in the container in the multiset container.
Below program illustrate the above-mentioned function:
// CPP program to demonstrate the// multiset::end() function#include <bits/stdc++.h>usingnamespacestd;intmain(){intarr[] = { 14, 10, 15, 11, 10, 12, 17, 12 };// initializes the set from an arraymultiset<int> s(arr, arr + 8);// prints all elements in setfor(autoit = s.begin(); it != s.end(); it++)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:10 10 11 12 12 14 15 17
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
Recommended Posts:
- unordered_multimap begin() and end() function in C++ STL
- match_results begin() and end() function in C++ STL
- array::begin() and array::end() in C++ STL
- deque::begin() and deque::end in C++ STL
- forward_list::begin() and forward_list::end() in C++ STL
- map::begin() and end() in C++ STL
- multimap::begin() and multimap::end() in C++ STL
- vector::begin() and vector::end() in C++ STL
- list::begin() and list::end() in C++ STL
- set::begin() and set::end() in C++ STL
- unordered_set begin() function in C++ STL
- unordered_multiset begin() function in C++ STL
- multiset rbegin() and rend() function in C++ STL
- multiset crbegin() and crend() function in C++ STL
- multiset cbegin() and cend() function in C++ STL
- multiset insert() function in C++ STL
- multiset find() function in C++ STL
- multiset equal_range() function in C++ STL
- multiset clear() function in C++ STL
- multiset empty() function in C++ STL
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.

