[Solved] C++ How to print this map std::map [closed]


So, a good first step is to actually write the example data such that it matches the type you’ve requested.

Perhaps something like:

Mymap[0] = {{{1, 3}, {1, 5}}, 4};
Mymap[1] = {{{2, 3}, {3, 7}, {1, 3}}, 8};

Then, we can pretty easily iterate over this…

#include <map>
#include <vector>
#include <iostream>

int main() {
    std::map<int, std::pair<std::vector<std::pair<int, int>>, int>> Mymap;

    Mymap[0] = {{{1, 3}, {1, 5}}, 4};
    Mymap[1] = {{{2, 3}, {3, 7}, {1, 3}}, 8};

    for (const auto & pair : Mymap) {
        for (const auto & pair : pair.second.first) {
            std::cout << "{" << pair.first << ", " << pair.second << "}, ";
        }
        std::cout << "\n";
    }
}

Which outputs:

{1, 3}, {1, 5}, 
{2, 3}, {3, 7}, {1, 3}, 

solved C++ How to print this map std::map>, int>> [closed]