---
title: "STL_Hash_map"
author: "vergilwang"
date: "2013-05-07T11:36:00Z"
tags: []
categories: ["编程语言"]
slug: "stl-hash-map"
draft: false
lastmod: "2014-02-15T14:34:29Z"
id: 2011203
url: "https://vergilwang.iteye.com/blog/2011203"
---

**在windows 和 linux下引入hash\_set、hash\_map头文件**

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

 

// just for "#include &lt;hash\_\*&gt;" in linux  
#if\_\_GNUC\_\_&gt;2  
#include&lt;ext/hash\_set&gt;  
#include&lt;ext/hash\_map&gt;  
usingnamespace\_\_gnu\_cxx;  
#else  
#include&lt;hash\_set&gt;  
#include&lt;hash\_map&gt;  
usingnamespacestdext;  
#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在哪个头文件中。

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