Answers for "c++ iterate map keys and values"

C++
2

cpp map iterate over keys

#include <iostream>
#include <map>

int main()
{
    std::map<std::string, int> myMap;

    myMap["one"] = 1;
    myMap["two"] = 2;
    myMap["three"] = 3;

    for ( const auto &myPair : myMap ) {
        std::cout << myPair.first << "\n";
    }
}
Posted by: Guest on April-08-2021
0

c++ iterate map

// C++11 and onwards
for (auto const& keyValue : map)
{
  keyValue.first; // Key
  keyValue.second; // Value
}
Posted by: Guest on December-03-2021

Code answers related to "c++ iterate map keys and values"

Browse Popular Code Answers by Language