map::end function


The map::end function returns an iterator pointing to one past the last element in the map container.

iterator end();
const_iterator end() const;

First function
Parameters:
none

Return type
iterator -A read and write iterator pointing to one past the last element in the container.

Second function
Parameters:
none

Return type
iterator -A read only iterator pointing to one past the last element in the container.

map end function

Code example

map<int ,string>mp{{2 , “Two” } , { 5 , “Five” } , { 0 , “Zero” }};

map<int,string>::iterator mpIt=mp.end();

mpIt->first=89 ; //error
mpIt->second=”Eighty nine” ; //doesn’t make any sense

cout<< mpIt->first << ” ” << mpIt->second << endl;

Assigning “Eighty nine” to mpIt->second doesn’t make any sense because mpIt points to invalid storage.Also accessing the first and second value of the pair element pointed by the mpIt is undefined.


 


Stop wasting time,earn money($$$) from your website-Join Now!