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 :: cpp execute command |
Cpp :: take a function argument |
Cpp :: how to sort array in c++ |
Cpp :: udo apt install dotnet-sdk-5 permission denied |
Cpp :: C++ Pi 4 Decimal |
Cpp :: c++ Attribute Parser |
Cpp :: trie code cpp |
Cpp :: convert ascii char value to hexadecimal c++ |
Cpp :: text color c++ |
Cpp :: onoverlapbegin ue4 c++ |
Cpp :: draw line sfml |
Cpp :: why use python |
Cpp :: c++ map lookup |
Cpp :: creating node in c++ |
Cpp :: c++ garbage collection |
Cpp :: Basic Input / Output in C++ |
Cpp :: Abstract factory C++ code |
Cpp :: integer max value c++ |
Cpp :: how to find factorial of number in c++ |
Cpp :: or in c++ |
Cpp :: c++ pointers and arrays |
Cpp :: how to sort string array in c++ |
Cpp :: split text c++ |
Cpp :: Implicit conversion casting |
Cpp :: queue cpp |
Cpp :: Programming Languages codechef solution in c++ |
Cpp :: Maximum Pairwise Modular Sum codechef solution in c++ |
Cpp :: how to run cpp in visual studio |
Cpp :: vector int initialize with increasing numbers |
Cpp :: cpp split bits |