Skip navigation.

The InterMa Style

The Way of Freedom

Posts tagged with "C++"

关于hash_map的使用

众所周知,hash_map目前不在C++98/2003标准中,因此在VC++2005和g++中使用的方法略有区别。
最重要的的hash函数的提供,看看例子就知道了:

【1】VC++2005
#include <hash_map>
using namespace stdext;

int main()
{
    hash_map<string, int> hmap;
    return 0;
}

【2】g++
#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;
}
December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31