I am looking for a template for hash map that i can rely on, and use whenever i need hash table. I was trying to use hash_map but found out that it is deprecated now.Tried using unordered_map, but i get the following error-
error: #error This file requires compiler and library support for the upcoming ISO C++ s tandard, C++0x. This support is currently experimental, and must be enabled with the -s td=c++0x or -std=gnu++0x compiler options.
Now, i am completely confused. I have been using hashmap in java, and it was pleasantly straight forward. It is not so in c++.
Guide me on what to use and how to use a hash table in c++.
hash_map(or rather,unordered_map, as it was called to avoid name collisions) is in the latest version of C++ (c++0x, or c++11) but many compilers, including yours, supported it before that. Your compiler is just being nice and stopping you from writing potentially non-portable code without your explicit consent.As the others say, adding
-std=c++0xto your compiler options will allow you to use hash_map,Do be aware that compiling that code somewhere else will require a rather modern c++ compiler.
(That might not be an issue for you.. if you’re just learning by yourself or not sharing the code outside your office, you should be fine…)