for(map<string, pair<string,string> >::const_iterator it = myMap.begin(); it != myMap.end(); ++it) { std::cout << it->first << " " << it->second.first << " " << it->second.second << "\n"; }
In C++11, you don’t need to spell out map<string, pair<string,string> >::const_iterator
. You can use auto
for(auto it = myMap.cbegin(); it != myMap.cend(); ++it) { std::cout << it->first << " " << it->second.first << " " << it->second.second << "\n"; }
Note the use of cbegin()
and cend()
functions.
Easier still, you can use the range-based for loop:
for(const auto& elem : myMap) { std::cout << elem.first << " " << elem.second.first << " " << elem.second.second << "\n"; }
Related Posts:
- C++ Loop through Map
- How to find if a given key exists in a C++ std::map
- Python AttributeError: ‘dict’ object has no attribute ‘append’
- I’m getting Key error in python
- Iterate through a C++ Vector using a ‘for’ loop
- Iterate through a C++ Vector using a ‘for’ loop
- How do I merge dictionaries together in Python?
- Simple dictionary in C++
- C++ for each, pulling from vector elements
- When is del useful in Python?
- What is C# equivalent of
- Iterate through a C++ Vector using a ‘for’ loop
- How to iterate through a list of objects in C++?
- Angular map. What is it?
- Map like structure in C: use int and struct to determine a value
- Python – How to fix “ValueError: not enough values to unpack (expected 2, got 1)”
- Dictionary text file
- How do I efficiently iterate over each entry in a Java Map?
- How to sort Map values by key in Java?
- Fill array with random numbers within a specified range (C++)
- Enhanced FOR loops in C++
- What is the difference between the HashMap and Map objects in Java?
- Printing an array in C++?
- “…redeclared as different kind of symbol”?
- Nested For – Loops to create multiplication table C++
- How can you print a variable name in python? [duplicate]
- How exactly do lookup tables work and how to implement them?
- Why are there no hashtables in the C standard library?
- Map vs Object in JavaScript
- How to iterate (keys, values) in JavaScript?
- Is “delete this” allowed in C++?
- What is a segmentation fault?
- How many spaces for tab character(\t)?
- How to create a dynamic array of integers
- How to create a dynamic array of integers
- Iterating over dictionaries using ‘for’ loops
- How to do associative array/hashing in JavaScript
- Linker Error C++ “undefined reference ” [duplicate]
- How do I sort a dictionary by value?
- How do I build a graphical user interface in C++? [closed]
- C++ convert from 1 char to string?
- How do I sort a dictionary by value?
- How do I build a graphical user interface in C++? [closed]
- convert a char* to std::string
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- system(“pause”); – Why is it wrong?
- Pause Console in C++ program
- How to implement 2D vector array?
- Why the switch statement cannot be applied on strings?
- What is the equivalent of the C++ Pair
in Java? - What is the difference between g++ and gcc?
- How to use setprecision in C++
- How to dynamically allocate arrays in C++
- How do I sort a dictionary by value?
- What does (~0L) mean?
- How to dynamically allocate arrays in C++
- What is the purpose of the return statement?
- What is the best way to use a HashMap in C++?
- What is the best way to use a HashMap in C++?
- What are the differences between a pointer variable and a reference variable in C++?
- Check if a given key already exists in a dictionary
- Why do we need virtual functions in C++?
- Why in C++ do we use DWORD rather than unsigned int? [duplicate]
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Sleep for milliseconds
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- What is the difference between float and double?
- Why is “using namespace std;” considered bad practice?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- Python for-in loop preceded by a variable
- What is the C++ function to raise a number to a power?
- Java 8 Iterable.forEach() vs foreach loop
- outputting ascii table in C++
- How to overcome TypeError: unhashable type: ‘list’
- What is a lambda expression in C++11?
- How does collections.defaultdict work?
- Vector of Vectors to create matrix
- How to use the PI constant in C++
- What is the difference between ++i and i++?
- How to throw a C++ exception
- std::string to char*
- How to generate a random number in C++?
- pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- How do I find the length of an array?
- Sleep for milliseconds
- How to convert string to char array in C++?
- C++ — expected primary-expression before ‘ ‘
- Using getline() with file input in C++
- What is the effect of extern “C” in C++?
- C++ Cout & Cin & System “Ambiguous” [closed]
- lvalue required as left operand of assignment error when using C++
- Loop through an array in JavaScript
- How do you create a dictionary in Java? [closed]
- ld: symbol(s) not found for architecture x86_64 error
- Python Dictionary Comprehension
- C++ string to double conversion