I want to traverse an STL map. I don\'t want to use its key. I don\'t care about the ordering, I just look for a way to access all elements it contains. How can I do this?
Using for
with auto
for C++11 and above usage
map map_variable; //you can use any data type for keys, as well as value
for(auto &x:map_variable)
{
cout<
The newer format of for
using auto
was introduced in C++11
To give it functionality like some higher level languages like python
Where there was already an implementation of such type of iteration
P.S. : map variable keeps values sorted, so when iterating you will get keys in sorted order