GCC中使用hash_map

GCC中使用hash_map_学着站在巨人的肩膀上_百度空间

GCC中使用hash_map

hash_map就是利用hash表实现的一个map,在查找是具有更快的效率,前提是你使用了适当的hash函数。hash_map不是STL中的一部分,但大多数C/c++的编译器都提供了这个容器。GCC也不例外,我在winds下使用的IDE是code blocks,它使用的编译器就是GCC。因为hash_map不是STL中的一部分,所以使用起来也不是很异样。下面的是我搜索到的一些资料: 【1】 http://zitronensaft.blogspot.com/2008/02/using-hashmap-on-gcc.html Using hash_map on GCC

If you have tried to use some STL containers with GCC, such as hash_map:

// error: hash_map: No such file or directory
#include <hash_map>

int main ()
{


// error: ‘hash_map’ is not a member of ‘std’
std ::hash_map <int ,int > hm ;

return 0 ;
}

Then you have realized that the code above does not compile. That's because on GCC, hash_map is not regarded as a standard container, but rather as a extension included in the __gnu_cxx namespace. In order to use hash_map and other extended containers with a minimum impact in your code (which is very important if it's intended to be cross-platform), you can use the following solution:
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif


namespace std
{

using namespace __gnu_cxx ;
}


int main ()
{


std ::hash_map <int ,int > hm ;

return 0 ;
}

Hope that helps.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值