在windows 和 linux下引入hash_set、hash_map头文件(转)

在windows 和 linux下引入hash_set、hash_map头文件(转)

推荐使用方法:在源代码的前面写入一下代码:

 

// just for "#include <hash_*>" in linux
#if __GNUC__>2
#include <ext/hash_set>
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_set>
#include <hash_map>
using namespace stdext;
#endif

 

其它解释和方法:

因为hash_map以前不属于标准库,而是后来引入的。

所以在windows下需要使用stlport,然后在setting中加入Additional library path。

在linux下使用gcc的时候,引入<hash_map>,使用的时候也说找不到hash_map,而这种后来引入标准库的有两种可能:
一种是它被放在了stdext名空间里,那么就要使用using namespace stdext引入该名空间并#include <hash_map>;
另一种可能就是它被放在标准库的ext目录底下,这时就仍旧需要使用属于std名空间,这时你的源文件应当#include <ext/hash_map>;
如果不知道是哪一种,就需要自己查一下,切换到c++库目录下:

cd /usr/include/c++/4.*.*

     然后使用grep命令:

grep -iR "hash_map" ./

    查看hash_map在哪个头文件中。

    找到后进去看一下就知道它到底被包含在哪个命名空间中了

你可能感兴趣的:(在windows 和 linux下引入hash_set、hash_map头文件(转))