Answers for "c++ how to iterate over map"

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

how to iterate from second element in map c++

it = map.begin();
++it;
for(; it != map.end(); ++it) {
    // do something
}

//shorter one:
it = ++map.begin();
Posted by: Guest on February-22-2022

Browse Popular Code Answers by Language