C++ map cend() FunctionC++ map cend() function is used to return a constant iterator which is next to the last entry in the map. Note:-This is a placeholder. No element exists in this location and attempting to access is undefined behavior.SyntaxNote: A const_iterator is an iterator that points to constant content.ParameterNone Return valueIt returns a constant iterator pointing next to the last element of the map. Example 1Let's see a simple example for cend() function. Output: mymap contains: [a:200] [b:100] [c:300] In the above example, cend() function is used to return an iterator pointing next to the last element in the mymap map. Example 2Let's see a simple example to iterate over the map using for-each loop. Output: Room1 = 100 Room2 = 200 Room3 = 300 In the above example, we are using an STL algorithm std::for-each to iterate over the map. It will iterate on each of the map element and call the callback provided by us. Example 3Let's see a simple example to iterate over the map using while loop. Output: 100 = Nikita 200 = Deep 300 = Priya 400 = Suman 500 = Aman In the above example, cend() function is used to return a constant iterator pointing next to the last element in the mymap map. Example 4Let's see a simple example. Output: Elements are: 10 + 10 = 20 20 + 20 = 40 30 + 30 = 60 end element (point next to the last): {3, 0} In the above example, cend() function is used to return a constant iterator pointing next to the last element in the mymap map. Next TopicC++ Map |
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