C++ unordered_map create
#include <iostream> #include <unordered_map> #include <string.h> using namespace std; struct eqstr// w ww .j a va 2 s . c o m { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } }; int main() { unordered_map<const char*, int, hash<const char*>, eqstr> Colors; Colors["Blue"] = 1; Colors["Green"] = 2; Colors["Teal"] = 3; Colors["Brick"] = 4; Colors["Purple"] = 5; Colors["Brown"] = 6; Colors["LightGray"] = 7; cout << "Brown = " << Colors["Brown"] << endl; cout << "Brick = " << Colors["Brick"] << endl; cout << "NotIn = " << Colors["NotIn"] << endl; }