VOOZH about

URL: https://www.geeksforgeeks.org/cpp/unordered_map-cbegin-in-c-stl/

⇱ unordered_map cbegin in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

unordered_map cbegin in C++ STL

Last Updated : 2 Jan, 2019
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 iterator pointing to the first element of the unordered_map. Below program illustrate the working of cbegin function:
Output:
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.
Output :
prog.cpp: In function 'int main()':
prog.cpp:18:20: error: assignment of member 'std::pair
Time Complexity: O(1) on average.
Comment