C++ multimap cend() functionThe C++ multimap cend() function is used to return a constant iterator which is next to the last entry in the multimap. Note:-This is a placeholder. No element exists in this location and attempting to access is undefined behavior.SyntaxA const_iterator is an iterator that points to constant content. ParameterNone Return valueIt returns a constant iterator which is pointing next to the last element of the multimap. ComplexityConstant. Iterator validityNo changes. Data racesThe container is accessed. Exception SafetyThis member function never throws exceptions. Example 1Let's see the simple example for cend() function: Output: mymultimap contains: [a:Java] [a:Android] [b:C++] [b:Python] In the above example, cend() function is used to return a const_ iterator pointing next to the last 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 100 = Deep 200 = Priya 200 = Aman 300 = Suman In the above example, cend() function is used to return a const_iterator pointing next to the last element in the mymultimap multimap. Example 4Let's see a simple example: Output: Elements are: 10 + 10 = 20 10 + 30 = 40 20 + 20 = 40 end element (point next to the last): {3, 0} In the above example, cend() function is used to return a const_iterator pointing next to the last element in the mymultimap multimap.
Next TopicC++ Multimap
|