I want to implement a function (findn) below that search on the std::map to find an element. However in my case the key is composite value, it is an
How do I use the std::map.find here?
#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(int argc, char** argv) {
insert(1,1,"test");
insert(1,1,"tes");
insert(1,2,"test 2");
std::cout << studentMap.size() << std::endl;
findn(1,1);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire