hash_map不在C++98/2003标准中,因此在VC++2005和g++中使用的方法略有区别。
【1】VC++2005
width="728" scrolling="no" height="90" frameborder="0" align="middle" src="http://download1.csdn.net/down3/20070601/01184120111.htm" marginheight="0" marginwidth="0">
【1】VC++2005
【2】g++#include <hash_map> // 注意头文件和namespace
using namespace stdext;
int main()
{
hash_map<string, int> hmap;
return 0;
}
#include <ext/hash_map>
using namespace __gnu_cxx;
// 需要自己写hash函数
struct string_hash
{
size_t operator()(const string& str) const
{
return __stl_hash_string(str.c_str());
}
};
int main()
{
hash_map<string, int, string_hash> hmap;
return 0;
}
width="728" scrolling="no" height="90" frameborder="0" align="middle" src="http://download1.csdn.net/down3/20070601/01184120111.htm" marginheight="0" marginwidth="0">