Answers for "how to loop in map in cpp"

C++
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
1

c++ map loop through key value

#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 << '\n';
    }
}
Posted by: Guest on January-12-2022

Browse Popular Code Answers by Language