在windows 和 linux下引入hash_set、hash_map標頭檔

來源:互聯網
上載者:User

在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在哪個標頭檔中。

    找到後進去看一下就知道它到底被包含在哪個命名空間中了

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.