Reputation: 2079
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++.
Upvotes: 1
Views: 1583
Reputation: 25710
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++0x
to 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...)
Upvotes: 3
Reputation: 4289
Just use -std=c++0x when you compile like your error message says! Anyhow the normal map interface in C++ is fairly optimized so unless performance is absolutely critical you should just use the map container.
Upvotes: 3
Reputation: 22703
Do what the error message says, invoke g++ as follows:
g++ -std=c++0x
Followed by the rest of the arguments.
Upvotes: 4