#include <iostream>
#include <vector>
#include <list>
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
The compiler says " hash_map: No such file or directory " Need help. thank you.
On MacOSX the correct header is at <ext/hash_map>
not <hash_map>
.
Here worked fine:
#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>
.
The <hash_map>
header is not part of the C++ standard and is a compiler-specific implementation. There's no guarantee that you'll be able to find it on any particular system, or that the various implementations that arise on each system will be mutually compatible with one another.
If you want to use a hash map in C++, you might want to look into boost::unordered_map
, tr1::unordered_map
, or a prototype C++0x compiler's implementation of std::unordered_map
. These implementations are fairly standardized, either by ISO or by the Boost community, and can easily be installed on most C++ compilers. I know that it's a bit presumptuous of me to just say "go rewrite this code using a different library," but given that C++ is about to gain hash containers of this form it's probably a worthwhile investment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With