Cannot find hash_map header under Mac OSX

#include <iostream> #include <vector> #include <list> #ifdef __GNUC__ #include <ext/hash_map> #else #include <hash_map> #endif 

The compiler says: "hash_map: there is no such file or directory" Help is needed. thanks.

+6
c ++ header macos
source share
2 answers

On MacOSX, the correct header is in <ext/hash_map> not <hash_map> . It works great here:

 #if defined __GNUC__ || defined __APPLE__ #include <ext/hash_map> #else #include <hash_map> #endif int main() { using namespace __gnu_cxx; hash_map<int, int> map; } 

By the way, I prefer to use <tr1/unordered_map> .

+12
source share

The <hash_map> header is not part of the C ++ standard and is a compiler specific implementation. There is no guarantee that you can find it in any particular system or that the various implementations that arise in each system will be mutually compatible with each other.

If you want to use the hash map in C ++, you may need to look at boost::unordered_map , tr1::unordered_map or a prototype implementation of the C ++ 0x compiler std::unordered_map . These implementations are fairly standardized by either the ISO or the Boost community, and can be easily installed on most C ++ compilers. I know that it's a little presumptuous to just say β€œrewrite this code with another library,” but given that C ++ is going to get hash containers of this form, this is probably worth the investment.

+5
source share

All Articles