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?
- How many spaces for tab character(\t)?
- How do I build a graphical user interface in C++? [closed]
- What is the purpose of the return statement?
- What are the differences between a pointer variable and a reference variable in C++?
- outputting ascii table in C++
- What is the effect of extern “C” in C++?
- Loop through an array in JavaScript
- no matching function for call to ‘ ‘
- Read file line by line using ifstream in C++
- Convert an int to ASCII character
- When should I write the keyword ‘inline’ for a function/method?
- C++ [Error] no matching function for call to
- When does a process get SIGABRT (signal 6)?
- Logical XOR operator in C++?
- C++ – Decimal to binary converting
- Alternative to itoa() for converting integer to string C++?
- 1e-9 or -1e9, which one is correct?
- Returning an empty string : efficient way in c++
- How can I create objects while adding them into a vector?
- What is the printf format specifier for bool?
- libpng warning: iCCP: known incorrect sRGB profile
- In CLion, header only library: file “does not belong to any project target, code insight features might not work properly”
- Is a function definition not allowed here before a ‘{‘ token?
- terminate called after throwing an instance of ‘std::out_of_range’
- What does “missing template argument” mean?
- Java – Best way to print 2D array?
- How do I call the class’s destructor?
- Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)
- Defining a struct in flex error C++
- C++ Postfix calculator using stacks
- LNK1168: cannot open debug\file.exe for writing
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- Can I output a one channel image acquired from camera into a winAppi window?
- Difference in make_shared and normal shared_ptr in C++
- Copy a file in a sane, safe and efficient way
- c++ convert string to hex
- LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
- How can I print variable and string on same line in Python?
- Multiple OR or AND conditions in IF statement
- What does it mean double free detected in tcache 2 while using mpz?
- What is the C equivalent to the C++ cin statement?
- c++ Read from .csv file
- Check if C++ Array is Null
- Random not declared in scope
- What does the “Expected ‘(‘ for function-style cast or type construction” error mean?
- LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
- Comparing the values of char arrays in C++
- Creating an instance of class
- How do I add a newline using printf?
- Destructor for a doubly-linked list that points to its value
- cin.ignore(numeric_limits
::max(), ‘\n’) - LLVM Compiler 2.0: Warning with “using namespace std;”
- C++ operator+ and operator+= overloading
- In c++ what does a tilde “~” before a function name signify?
- ERROR: Control may reach end of non-void function /
- Function stoi not declared
- What’s the difference between while(cin) and while(cin >> num)
- Too many arguments to function
- not declared in this scope’ when using strlen()
- Converting a Cubemap into Equirectangular Panorama
- Why is this vector iterator not incrementable?
- glibc detected : double free or corruption
- What is the best way to develop a C++ web application?
- How to install Visual Studio Build Tools 2010 on Visual Studio 2015 Community?
- Visual c++ can’t open include file ‘iostream’
- c++ vector bubble sort
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- compare and swap vs test and set
- Weighted random numbers
- compare and swap vs test and set