C++11 使用复合键搜索 std::map

C++11 search an std::map with composite key

我想在 std::map 的搜索下方实现一个函数 (findn) 以查找元素。但是在我的例子中,键是复合值,它是一个 <int,int>

如何使用这里的std::map.find

#include <iostream>
#include <map>
#include <utility>
#include <string>

using namespace std;

std::map<std::pair<int, int>, std::string> studentMap;

int insert(int i, int j, std::string name) {
        if( !studentMap.insert( std::make_pair ( std::make_pair(i,j), name)).second ) { 
                std::cout << "game not added" << std::endl;
        } else {
                std::cout << "game added" << std::endl;
        }
        return 0;
}

void findn(int i, int j) {
// how to find when we have composite key?
}

int main() {
        insert(1,1,"test");
        insert(1,1,"tes");
        insert(1,2,"test 2");

        std::cout << studentMap.size() << std::endl;
        findn(1,1);
}

这将完成工作:

auto it = mymap.find(std::make_pair(i,j));