user5304744
user5304744

Reputation:

C++ Outputting a map

What is the easiest way to output a map?

map < int , string > BIG_MAP;

The method I use for insertion is:

BIG_MAP[x] = y;

I can't find any way which works.

Upvotes: 0

Views: 91

Answers (1)

therainmaker
therainmaker

Reputation: 4343

What you are looking for is a way to print a map. All you need to do is to iterate over all its elements and print them one by one. Now that question comes how do you iterate over the elements? For that you can either use an iterator BIG_MAP.begin() and increment it till you reach BIG_MAP.end(). You can also use the range based for loop shown below.

for (auto x: map)
  cout << x.first << " " << x.second << endl;

Upvotes: 1

Related Questions