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 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_multiset container.

Return Value: It returns a constant iterator. It cannot be used to change the value of the unordered_multiset element.

Below programs illustrates the above function:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::cbegin() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<int> sample;
  
    // inserts element
    sample.insert(10);
    sample.insert(11);
    sample.insert(15);
    sample.insert(13);
    sample.insert(14);
  
    // prints all element
    cout << "Elements: ";
    for (auto it = sample.cbegin(); it != sample.cend(); it++)
        cout << *it << " ";
  
    auto it = sample.cbegin();
  
    // print the first element
    cout << "\nThe first element: " << *it;
  
    return 0;
}

chevron_right


Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::cbegin() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<char> sample;
  
    // inserts element
    sample.insert('a');
    sample.insert('b');
    sample.insert('c');
    sample.insert('x');
    sample.insert('z');
  
    // print the first element
    auto it = sample.cbegin();
    cout << "The first element: " << *it;
  
    it++;
    cout << "\nThe second element: " << *it;
  
    cout << "\nElements: ";
  
    // prints all element
    for (auto it = sample.cbegin(); it != sample.cend(); it++)
        cout << *it << " ";
    return 0;
}

chevron_right


Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::cbegin() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<char> sample;
  
    // inserts element
    sample.insert('a');
    sample.insert('b');
    sample.insert('c');
    sample.insert('x');
    sample.insert('z');
  
    // print the first element
    cout << "The first element in first bucket : " << *sample.cbegin(1);
  
    cout << "\nElements in first bucket: ";
  
    // prints all element
    for (auto it = sample.cbegin(1); it != sample.cend(1); it++)
        cout << *it << " ";
    return 0;
}

chevron_right




My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.