Skip navigation.

The InterMa Style

The Way of Freedom

关于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;
}

配合CVS作补丁 InterMa笑话集 第三期

Comments

bitstream 13. April 2007, 08:25

呵呵,g++中的还带个函数对象啊~不过我还没用过hash_map。

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

January 2010
S M T W T F S
December 2009February 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