Jenna Davis Jenna Davis - 27 days ago 7
C++ Question

How to output a map with a vector of pairs?

I have the following map;

std::map<long, std::vector<std::pair<long,long>>> G;


I'm having trouble figuring out how to print the pair values in it, could anyone help me out?

Answer

Try a loop:

for (const auto & p : G)
{
    std::cout << p.first << " => {";
    for (const auto & q : p.second)
        std::cout << "(" << q.first << ", " << q.second << ")";
    std::cout << "}\n";
}
Comments