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 :: c++ set console title |
Cpp :: infinity c++ |
Cpp :: error: ‘memset’ was not declared in this scope in cpp |
Cpp :: ue4 ftext c++ |
Cpp :: grpah class data structure |
Cpp :: multiply two Mat in c++ element per element |
Cpp :: cv2.threshold c++ |
Cpp :: collections c# vs c++ |
Cpp :: insert at position in vector c++ |
Cpp :: gl draw line rectangle |
Cpp :: char type casting in c++ |
Cpp :: c++ vector combine two vectors |
Cpp :: creator of C++ |
Cpp :: temporary mobile number |
Cpp :: border radius layout android xml |
Cpp :: c++ check open processes |
Cpp :: c++ find key in hashmap |
Cpp :: quick sort c++ |
Cpp :: c++ print byte as bit |
Cpp :: resize two dimensional vector c++ |
Cpp :: remove at index vector c++ |
Cpp :: C++ mutex lock/unlock |
Cpp :: to_string c++ |
Cpp :: online cpp to exe converter |
Cpp :: how to convert int to string c++ |
Cpp :: c++ length of char* |
Cpp :: chrono start time in c++ |
Cpp :: c++ constructors |
Cpp :: memcpy c++ usage |
Cpp :: max element in array c++ stl |