zoukankan      html  css  js  c++  java
  • 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.htmlUsing 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.

  • 相关阅读:
    第一周作业
    第一次作业
    第八周作业
    第七周作业
    第六周作业
    第五周作业
    第四周作业
    第三周作业
    第二周作业
    第一周作业2
  • 原文地址:https://www.cnblogs.com/lexus/p/2771342.html
Copyright © 2011-2022 走看看