So I have a map like this:
map<string, pair<string,string> > myMap;
And I've inserted some data in my map using:
myMap.insert(make_pair(first_name, make_pair(middle_name, last_name)));
My question is, how do I print out all the data in my map? Please provide an example for my reference.
In C++11, you don't need to spell out
map<string, pair<string,string> >::const_iterator
. You can useauto
Note the use of
cbegin()
andcend()
functions.Easier still, you can use the range-based for loop:
If your compiler supports (at least part of) C++11 you could do something like:
For C++03 I'd use
std::copy
with an insertion operator instead: