← Back to STL Containers
Question 567
Iterate a Map with Iterators
Iterate a Map with Iterators
Amap<string, int>namedstockhas already been created withapplemapped to 3 andpearmapped to 5. Write an iterator loop fromstock.begin()tostock.end()that prints one line per entry in the format key, colon, space, value (see Expected Output). Each line ends with a newline. Do not use a range-based for loop — usebegin()/end()and the->operator.
Expected Output:
apple: 3 pear: 5
= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
STL ContainersIterators
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.