
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
multiset cbegin() and cend() function in C++ STL
In this article we will be discussing the working, syntax and examples of multiset::cbegin() and multiset::cend() function in C++ STL.
What is a multiset in C++ STL?
Multisets are the containers similar to the set container, meaning they store the values in the form of keys same like a set, in a specific order.
In multiset the values are identified as keys as same as sets. The main difference between multiset and set is that the set has distinct keys, meaning no two keys are the same, in multiset there can be the same keys value.
Multiset keys are used to implement binary search trees.
What is multiset::cbegin()?
multiset::cbegin() function is an inbuilt function in C++ STL, which is defined in <set> header file. cbegin() means constant begin function, means this function returns the constant iterator pointing to the beginning of the multiset container.
The constant iterator can be just used for iterating through the multiset container, this can’t make changes in the multiset container.
Syntax
ms_name.cbegin();
Parameters
The function accepts no parameter.
Return value
This function returns a constant iterator which is pointing to the first element of the container.
Example
Input
std::multiset<int> mymultiset = {1, 2, 2, 3, 4}; mymultiset.cbegin();
Output
1
Example
#include <bits/stdc++.h> using namespace std; int main() { int arr[] = {10, 20, 30, 40, 50, 60}; multiset<int> check(arr, arr + 6); cout<<"First element fetched using cbegin() function: "<<*(check.cbegin()) << endl; for(auto i = check.cbegin(); i!= check.cend(); i++) cout << *i << " "; return 0; }
Output
First element fetched using cbegin() function: 10 10 20 30 40 50 60
What is multiset::cend()?
multiset::cend() function is an inbuilt function in C++ STL, which is defined in <set> header file. cend() means constant end function, means this function returns the constant iterator pointing to past the last element of the multiset container.
The constant iterator can be just used for iterating through the multiset container, this can’t make changes in the multiset container.
Syntax
ms_name.cend();
Parameters
The function accepts no parameter.
Return value
This function returns a constant iterator which is pointing to the element past the last of the container.
Example
Input
std::multiset<int&t; mymultiset = {1, 2, 2, 3, 4}; mymultiset.cend();
Output
error
Example
#include <bits/stdc++.h> using namespace std; int main() { int arr[] = {10, 20, 30, 40, 50, 60}; multiset<int> check(arr, arr + 6); cout<<"Elements in the list are: "; for(auto i = check.cbegin(); i!= check.cend(); i++) cout << *i << " "; return 0; }
Output
Elements in the list are: 10 20 30 40 50 60
- Related Articles
- Set cbegin() and cend() function in C++ STL
- map cbegin() and cend() function in C++ STL
- list cbegin() and cend() functions in C++ STL
- multimap::cbegin() and multimap::cend() in C++ STL
- match_results cbegin() add cend() in C++ STL
- multiset begin() and end() function in C++ STL
- multiset crbegin() and crend() function in C++ STL
- multiset insert() function in C++ STL
- multiset clear() function in C++ STL
- multiset count() function in C++ STL
- multiset empty() function in C++ STL
- Multiset emplace_hint() function in C++ STL
- multiset equal_range() function in C++ STL
- forward_list cbegin() in C++ STL
- forward list::cend() in C++ STL
