hashmap - I would like to see a hash_map example in C++ -
I do not know how to use the hash function in C ++, but I know that we have the Hash_map
. G ++, which only includes #include & lt; Hash_map & gt;
included? hashmap
?
Using a current C ++ standard What is a simple example? There are hash maps, but the C ++ 0x standard approaches, and they are already supported by G ++ in the shape of "unordered maps":
#include & lt; Unordered_map> # Include & lt; Iostream & gt; #include & lt; String & gt; using namespace std; Int main () {unordered_map & lt; String, int & gt; Meter; I ["foo"] = 42; Cout & lt; & Lt; I ["Foo"]
To achieve this compilation, you must tell G ++ that you are using C ++ 0x:
G ++ -STD = C ++ 0x main.cpp
These maps work a lot as a studs :: map, except that a custom operator & lt ; ()
For your own type, you need to provide a custom hash function - appropriate functions are provided for the type of integer and string.
Comments
Post a Comment