linux hash_map

时间:2023-03-09 03:48:05
linux hash_map

在linux下的hash_map

hash_map本身以前本身不属于标准库,是后来引入的.
有两种可能:
一种可能它被放在了stdext名空间里,那么你就要使用using namespace stdext 引入该名空间并#include <hash_map>;.
另一种可能就是它被反在了标准库的ext目录底下,仍旧属于std名空间
这时你的源文件应当包含头文件
#include <ext/hash_map>;

如果不知道的话.可以使用
切换到你的stl库目录底下cd /usr/include/c++/版本
然后grep -iR "hash_map" ./
查看在哪个文件中.一般头文件的最后几行会提示它所述的名空间.

  1. #ifndef _HASH_MAP
  2. #define _HASH_MAP 1
  3. #include <ext/hashtable.h>;
  4. #include <bits/concept_check.h>;
  5. namespace __gnu_cxx  //这儿说明它属于__gnu_cxx名空间.
  6. {
  7. using std::equal_to;
  8. using std::allocator;
  9. ........

复制代码

我的头文件如上,所以它是属于__gnu_cxx名空间.
加上using namespace __gnu_cxx就可以了.

看你的头文件是什么,这几个模板本身就是在各个STL库实现都不一样.看一下源文件,在引入相应的名空间就可以了.