What is the best way to use two keys with a std::map?

后端 未结 9 1832
你的背包
你的背包 2021-01-30 03:54

I have a std::map that I\'m using to store values for x and y coordinates. My data is very sparse, so I don\'t want to use arrays or vectors, which would result in

9条回答
  •  余生分开走
    2021-01-30 04:36

    Use std::pair for the key:

    std::map, int> myMap;
    
    myMap[std::make_pair(10,20)] = 25;
    std::cout << myMap[std::make_pair(10,20)] << std::endl;
    

提交回复
热议问题