The Wayback Machine - https://web.archive.org/web/20241203102846/https://www.geeksforgeeks.org/multiset-cbegin-and-cend-function-in-c-stl/
Open In App

multiset cbegin() and cend() function in C++ STL

Last Updated : 10 Jul, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The multiset::cbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the first element in the container. The iterator cannot be used to modify the elements in the set container. The iterators can be increased or decreased to traverse the set accordingly. 

Syntax: 

constant_iterator multiset_name.cbegin()

Parameters: The function does not accept any parameters.

Return value: The function returns a constant iterator pointing to the first element in the container. 

Below programs illustrate the multiset::cbegin() method.

C++




// C++ program to demonstrate the
// multiset::cbegin() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
 
    int arr[] = { 14, 10, 15, 11, 10 };
 
    // initializes the set from an array
    multiset<int> s(arr, arr + 5);
 
    // Prints the first element
    cout << "The first elements is: " << *(s.cbegin()) << endl;
 
    // prints all elements in set
    for (auto it = s.cbegin(); it != s.cend(); it++)
        cout << *it << " ";
 
    return 0;
}


Output: 

The first elements is: 10
10 10 11 14 15

 

The multiset::cend() is a built-in function in C++ STL which returns a constant iterator pointing to the position past the last element in the container. The iterator cannot be used to modify the elements in the set container. The iterators can be increased or decreased to traverse in the set accordingly. 

Syntax: 

constant_iterator multiset_name.cend()

Parameters: The function does not accept any parameters.

Return value: The function returns a constant iterator pointing to the position past the last element in the container in the container. 

Below programs illustrate the multiset::cend() method.

C++




// C++ program to demonstrate the
// multiset::cend() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
 
    int arr[] = { 14, 10, 15, 11, 10, 15, 17, 17 };
 
    // initializes the set from an array
    multiset<int> s(arr, arr + 8);
 
    // prints all elements in set
    for (auto it = s.cbegin(); it != s.cend(); it++)
        cout << *it << " ";
 
    return 0;
}


Output: 

10 10 11 14 15 15 17 17

 

Let us see the differences in a tabular form -:

  multiset cbegin() multiset cend()
1. It is used to return a const_iterator pointing to the first element in the container. It is used to return  a const_iterator pointing to the past-the-end element in the container.
2.

Its syntax is -:

const_iterator cbegin();

Its syntax is -:

const_iterator cend();

3. It does not take any parameters  It does not take any parameters.
4. Its complexity is constant. Its complexity is constant.
5. Its iterator validity does not changes. Its iterator validity does not changes.

 



Next Article

Similar Reads

list cbegin() and cend() function in C++ STL
The list::cbegin() is a built-in function in C++ STL which returns a constant random access iterator which points to the beginning of the list. Hence the iterator obtained can be used to iterate container but cannot be used to modify the content of the object to which it is pointing even if the object itself is not constant.Syntax: list_name.cbegin
2 min read
map cbegin() and cend() function in C++ STL
map::cbegin() is a built-in function in C++ STL that returns a constant iterator referring to the first element in the map container. Since map container contains the element in an ordered way, cbegin() will point to that element that will come first according to the container's sorting criterion. Syntax: map_name.cbegin()Parameters: The function d
3 min read
set cbegin() and cend() function in C++ STL
The set::cbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the first element in the container. The iterator cannot be used to modify the elements in the set container. The iterators can be increased or decreased to traverse the set accordingly. Syntax: constant_iterator set_name.cbegin() Parameters: The functi
2 min read
vector :: cbegin() and vector :: cend() in C++ STL
Vectors are known as dynamic arrays which can change its size automatically when an element is inserted or deleted. This storage is maintained by container. vector::cbegin() The function returns an iterator which is used to iterate container. The iterator points to the beginning of the vector.Iterator cannot modify the contents of the vector. Synta
2 min read
array::cbegin() and array::cend() in C++ STL
array::cbegin() is a built-in function in C++ STL which returns a const_iterator pointing to the first element in the array. It cannot be used to modify the element in the array which is possible using array::begin(). Syntax: array_name.cbegin() Parameters: The function does not accept any parameters. Return Value: The function returns a const_iter
2 min read
multimap::cbegin() and multimap::cend() in C++ STL
multimap::cbegin() is a built-in function in C++ STL which returns a constant iterator referring to the first element in the multimap container. Since multimap container contains the element in an ordered way, cbegin() will point to that element that will come first according to the container's sorting criterion. Syntax: multimap_name.cbegin()Param
3 min read
match_results cbegin() add cend() in C++ STL
match_results::cbegin() is an inbuilt function in C++ STL which returns a constant iterator that points to the first match in the match_results object. This iterator cannot modify the contents of the vector. Syntax:smatch_name.cbegin()Parameters: This function does not accept any parameters.Return value: This function returns a constant iterator po
2 min read
unordered_set cend() function in C++ STL
The unordered_set::cend() method is a built-in function in C++ STL which is used to return a const_iterator pointing to past-the-end element in the unordered_set container or in one of it's bucket. This function does not directly point to any element in the container. It is only used to denote the end of a container or the open end of a range as in
2 min read
unordered_multiset cend() function in C++ STL
The unordered_multiset::cend() is a built-in function in C++ STL which returns a constant iterator pointing to the position immediately after the last element in the container or to the position immediately after the last element in one of its bucket. Syntax: unordered_multiset_name.cend(n) Parameters: The function accepts one parameter. If a param
2 min read
unordered_multimap cend() function in C++ STL
The unordered_multimap::cend() is a built-in function in C++ STL which returns a constant 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.cend(n) Parameters: The function accepts one parameter. If a parameter is passed, it retur
2 min read
unordered_set cbegin() function in C++ STL
The unordered_set::cbegin() method is a built-in function in C++ STL which is used to return a const_iterator pointing to the first element in the unordered_set container. This iterator can point to either the very the first element or first element of any specified bucket in the unordered_set container. Note: A const_iterator can only be used to a
2 min read
unordered_multiset cbegin() function in C++ STL
The unordered_multiset::cbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the first element in the container or to the first element in one of its bucket. Syntax: unordered_multiset_name.cbegin(n) Parameters: The function accepts one parameter. If a parameter is passed, it returns a constant iterator pointing
2 min read
unordered_multimap cbegin() function in C++ STL
The unordered_multimap::cbegin() is a built-in function in C++ STL which returns a constant iterator pointing to the first element in the container or to the first element in one of its bucket. Syntax: unordered_multimap_name.cbegin(n) Parameters: The function accepts one parameter. If a parameter is passed, it returns a constant iterator pointing
2 min read
forward_list::cend() in C++ STL with Example
forward_list::cend() is a function in C++ STL which returns a constant iterator pointing to the past-the-last element of the forward_list. The iterator returned by the function does not point to any element in the container, but to the position followed by the last element of the forward list container. The iterator returned by the function points
2 min read
unordered_map cend in C++ STL
The unordered_map::cend() is a built-in function in C++ STL which returns an iterator pointing to the position past the end element in the container or in one of its bucket. In an unordered_map object, there is no guarantee that which specific element is considered its first element. But all the elements in the container are covered since the range
3 min read
forward_list cbegin() in C++ STL
The forward_list::cbegin() is a function in C++ STL which returns a constant iterator pointing to the first element of the forward_list. Syntax: forward_list_name.cbegin() Parameters: This function does not accept any parameter. Return Value: This function returns an iterator that points to the const content. Since the iterator is not constant it c
2 min read
deque cbegin() in C++ STL
The cbegin() method in deque is a function in C++ STL which returns an iterator pointing to the first element of the container. Syntax: deque_name.cbegin() Return value: It returns a constant iterator pointing to the first element of the deque. This means, that the iterator can be used to traverse the queue, but not to modify it. That is, functions
2 min read
unordered_map cbegin in C++ STL
cbegin function in c++ is used to return a constant iterator pointing the first element in an unordered map. Syntax: unordered_map.cbegin() Parameter: It takes an optional parameter N. If set, the iterator returned will point to the first element of the bucket otherwise it point to the first element of the container. Return values: A constant itera
2 min read
multiset rbegin() and rend() function in C++ STL
multiset::rbegin() is a built-in function in C++ STL which returns a reverse iterator pointing to the last element in the multiset container. Syntax: reverse_iterator multiset_name.rbegin() Parameters: The function does not take any parameter. Return value: The function returns a reverse iterator pointing to the last element in the container. Below
2 min read
multiset crbegin() and crend() function in C++ STL
The multiset::crbegin() is a built-in function in C++ STL which returns a constant reverse iterator pointing to the last element in the container. The iterator cannot be used to modify the elements in the multiset container. The iterators can be increased or decreased to traverse the set accordingly. Syntax: constant_reverse_iterator multiset_name.
2 min read
multiset begin() and end() function in C++ STL
The multiset::begin() is a built-in function in C++ STL that 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 a
2 min read
multiset insert() function in C++ STL
The multiset::insert() is a built-in function in C++ STL which insert elements in the multiset container or inserts the elements from a position to another position from one multiset to a different multiset. Syntax: iterator multiset_name.insert(element)Time Complexity: O(log n) Since the elements are always in sorted order, the newly inserted elem
4 min read
multiset find() function in C++ STL
The multiset::find() is a built-in function in C++ STL which returns an iterator pointing to the lower_bound of the element which is searched in the multiset container. If the element is not found, then the iterator points to the position past the last element in the set. Syntax: multiset_name.find(element) Parameters: The function accepts one mand
2 min read
multiset equal_range() function in C++ STL
The multiset::equal_range() is a built-in function in C++ STL which returns an iterator of pairs. The pair refers to the range that includes all the elements in the container which have a key equivalent to k. The lower bound will be the element itself and the upper bound will point to the next element after key k. If there are no elements matching
3 min read
multiset clear() function in C++ STL
The multiset::clear() function is a built-in function in C++ STL which removes all elements from the multiset container. The final size of multiset container after removal is 0. Syntax: multiset_name.clear() Parameters: The function does not accept any parameter. Return Value: The function does not returns anything. Below programs illustrates the m
2 min read
multiset empty() function in C++ STL
The multiset::empty() function is a built-in function in C++ STL which checks if the multiset is empty or not. It returns true if the multiset is empty, else it returns false. Syntax: multiset_name.empty() Parameters: The function does not accept any parameter. Return Value: The function returns true if the multiset is empty, else it returns false.
1 min read
multiset count() function in C++ STL
The multiset::count() function is a built-in function in C++ STL that searches for a specific element in the multiset container and returns the number of occurrences of that element. Syntax: multiset_name.count(val) Parameters: The function accepts a single parameter val which specifies the element to be searched in the multiset container. Return V
2 min read
multiset emplace_hint() function in C++ STL
The multiset::emplace_hint() is a built-in function in C++ STL which inserts a new element in the multiset. A position is passed in the parameter of the function which acts as a hint from where the searching operation starts before inserting the element at its current position. The position only helps the process to get faster, it does not decide w
3 min read
multiset get_allocator() function in C++ STL
The multiset::get_allocator() method in C++ STL is a built-in function in C++ STL which returns a copy of the allocator object associated with the multiset. Syntax: multiset_name.get_allocator() where allocator_type is the type of the allocator used by the container. Parameters: The function does not take any parameter. Return Value: This method re
1 min read
cend() Function in C++
Cend() is the function defined in C++ STL. This function produces a constant random access iterator that identifies the deque's past-the-end element. If the container is empty then cend() function returns the same as cbegin() function. This member function's iterator can only be used to iterate containers; it cannot be used to change the content of
2 min read
Practice Tags :