Search code examples
c++arraysdictionary2d

How to make a 2D map similar to a 2D array


Is it possible to make a 2d map?

Like this:

map< int, int, string> testMap;

And filling the values would be like:

testMap[1][3] = "Hello";

Solution

  • yes, use std::pair within a std::map,

    std::map< std::pair<int, int>, string> testMap;
    testMap[std::make_pair(1,3)] = "Hello";