There is no hash map in the current C ++ standard, but the following C ++ 0x standard does, and they are already supported by g ++ in the form of "unordered maps":
#include <unordered_map> #include <iostream> #include <string> using namespace std; int main() { unordered_map <string, int> m; m["foo"] = 42; cout << m["foo"] << endl; }
To get this compiler, you need to tell g ++ that you are using C ++ 0x:
g++ -std=c++0x main.cpp
These maps work almost the same as std :: map, except that instead of providing a custom operator<() for your own types, you need to provide a custom hash function - for types such as integers and strings, the corresponding functions.
anon Feb 01 '10 at 20:50 2010-02-01 20:50
source share