The question is self-explanatory. But to complement suppose: map<int,int> with at least 10 inserted elements. What is the correct way to delete the last inserted element?
By the last element inserted I mean, not the last element of the map, but the element that I inserted the last time I inserted an element.
Save an iterator to the last inserted element. The elements in the map are ordered by the key values, not by insertion order.
map::insertreturns an iterator to the last inserted element (and aboolindicating if an insertion took place).http://en.cppreference.com/w/cpp/container/map/insert