cbegin function in c++ is used to return a constant iterator pointing the first element in an unordered map.
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 iterator pointing to the first element of the unordered_map.
Below program illustrate the working of cbegin function:
Contents of the unordered_map : s==>>5 k==>>4 g==>>1 e==>>2
The cbegin() function returns a constant iterator. If we try to change value, we get compiler error.
prog.cpp: In function 'int main()': prog.cpp:18:20: error: assignment of member 'std::pair
, int>::second' in read-only object it->second = 10; // This would cause compiler error ^
Time Complexity: O(1) on average.
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.
- vector :: cbegin() and vector :: cend() in C++ STL
- list cbegin() and cend() function in C++ STL
- array::cbegin() and array::cend() in C++ STL
- multimap::cbegin() and multimap::cend() in C++ STL
- map cbegin() and cend() function in C++ STL
- unordered_set cbegin() function in C++ STL
- unordered_multiset cbegin() function in C++ STL
- forward_list cbegin() in C++ STL
- unordered_multimap cbegin() function in C++ STL
- match_results cbegin() add cend() in C++ STL
- deque cbegin() in C++ STL
- multiset cbegin() and cend() function in C++ STL
- set cbegin() and cend() function in C++ STL
- unordered_map in C++ STL
- fill() and fill_n() functions in C++ STL
- std::transform() in C++ STL (Perform an operation on all elements)
- Array algorithms in C++ STL (all_of, any_of, none_of, copy_n and iota)
- Iterators in C++ STL
- accumulate() and partial_sum() in C++ STL : numeric header
- std::partition 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 firstname.lastname@example.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.