#include <iostream>
#include <vector>
#include <list>
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
編譯器說「的hash_map:沒有這樣的文件或目錄 」 需要幫助。謝謝。不能在Mac OSX找到了hash_map頭
#include <iostream>
#include <vector>
#include <list>
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
編譯器說「的hash_map:沒有這樣的文件或目錄 」 需要幫助。謝謝。不能在Mac OSX找到了hash_map頭
在MacOSX上,正確的標題是<ext/hash_map>
而不是<hash_map>
。 這裏工作得很好:
#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;
}
順便說一句,我更喜歡使用<tr1/unordered_map>
。
<hash_map>
頭文件不是C++標準的一部分,是編譯器特定的實現。不能保證您能夠在任何特定系統上找到它,或者每個系統上出現的各種實現將相互兼容。
如果要在C++中使用哈希映射,您可能需要查看boost::unordered_map
,tr1::unordered_map
或原型C++ 0x編譯器的std::unordered_map
實現。這些實現相當標準化,可以由ISO或Boost社區實現,並且可以很容易地安裝在大多數C++編譯器上。我知道我只是說「用一個不同的庫重寫這段代碼」是有點冒失的,但考慮到C++將要獲得這種形式的哈希容器,這可能是一個值得的投資。
在你的指南之後,我仍然沒有在這個範圍內聲明「'hash_map'」。 – 2011-02-09 22:29:00