C++ multimap cbegin() functionThe C++ multimap cbegin() function is used to return a constant iterator pointing to the first element of the multimap container. SyntaxA const_iterator is an iterator that points to constant content. ParameterNone Return valueIt returns a const_iterator pointing to the first element of the multimap. ComplexityConstant Iterator ValidityNo changes. Data RacesThe container is accessed. Exception SafetyThis member function never throws exception. Example 1Let's see the simple example for cbegin() function: Output: a => Java a => Android b => C++ b => Python In the above example, cbegin() function is used to return a const_iterator pointing to the first element in the mymultimap multimap. Example 2Let's see a simple example to iterate over the multimap using for-each loop: Output: Room1 = 100 Room1 = 300 Room1 = 100 Room2 = 200 In the above example, we are using an STL algorithm std::for-each to iterate over the multimap. It will iterate on each of the multimap element and call the callback provided by us. Example 3Let's see a simple example to iterate over the multimap using while loop: Output: 100 = Nikita 200 = Deep 200 = Suman 300 = Priya 400 = Aman In the above example, cbegin() function is used to return a const_iterator pointing to the first element in the mymultimap multimap. Example 4Let's see another simple example: Output: The first element of m1 is 0 First element of m1 is now 1 In the above example, cbegin() function is used to return a const_iterator pointing to the first element in the mymultimap multimap. Next TopicC++ Multimap |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India