for (auto i = myMap.begin(); i != myMap.end(); ++i) {
cout << i->first << ": " << i->second << endl;
}
// C++17 and above
for (auto const& [key, value] : map)
{
// do something
}
#include <iostream>
#include <map>
int main() {
std::map<std::string, int> myMap;
myMap["one"] = 1;
myMap["two"] = 2;
myMap["three"] = 3;
for ( const auto &[key, value]: myMap ) {
std::cout << key << '
';
}
}
// C++11 and onwards
for (auto const& keyValue : map)
{
keyValue.first; // Key
keyValue.second; // Value
}
for (auto i : m)
cout << i.first << " " << i.second
<< endl;
void output(map<string, int> table)
{
map<string, int>::iterator it;
for (it = table.begin(); it != table.end(); it++)
{
//How do I access each element?
}
}
Code Example |
---|
Cpp :: flake8 max line length |
Cpp :: how to print items in arduino |
Cpp :: sort a vector of strings according to their length c++ |
Cpp :: torch cuda is available |
Cpp :: set platformio to C++17 |
Cpp :: log base c++ |
Cpp :: c++ delete directory |
Cpp :: colourful text in c++ |
Cpp :: sfml set font |
Cpp :: linked list with classes c++ |
Cpp :: c++ pause |
Cpp :: sum vector c++ |
Cpp :: C++ Kelvin to Celsius |
Cpp :: cpp executing without console |
Cpp :: c++ index of nth occurence |
Cpp :: vs code text in line |
Cpp :: integer to string c++ |
Cpp :: qt qmessagebox |
Cpp :: differency between c++ std and stl |
Cpp :: print queue c++ |
Cpp :: delete specific vector element c++ |
Cpp :: #pragma once in main file what is it for |
Cpp :: is C++ useful in 2021 |
Cpp :: c++ print every element in array |
Cpp :: OPA in expanse |
Cpp :: how to declare 1-D array in C/C++ |
Cpp :: c++ shared pointer |
Cpp :: default access modifier in c++ |
Cpp :: maximum int c++ |
Cpp :: time function c++ |