Answers for "c++ update map value iterate"

C++
1

how to iterater map of sets in c++

map<string, set<string>> mp;
     for (auto const& pair : mp) {
         cout << pair.first << ": ";
         for (auto const& elem : pair.second) {
             cout << elem << ", ";
         }
         cout << "\n";
     }
Posted by: Guest on July-30-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