首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++中的hash_地图和地图的区别

2013-10-21 
C++中的hash_map和map的区别#if defined(__GNUC__)#if __GNUC__ 3 && __GNUC__ 2 && __GNUC_MINOR__

C++中的hash_map和map的区别
#if defined(__GNUC__) #if __GNUC__ < 3 && __GNUC__ >= 2 && __GNUC_MINOR__ >= 95 #include <hash_map> #elif __GNUC__ >= 3 #include <ext/hash_map> using namespace __gnu_cxx; #else #include <hash_map.h> #endif #elif defined(__MSVC_VER__) #if __MSVC_VER__ >= 7 #include <hash_map> #else #error "std::hash_map is not available with this compiler" #endif #elif defined(__sgi__) #include <hash_map> #else #error "std::hash_map is not available with this compiler" #endif #include <string> #include <iostream> #include <algorithm> using namespace std; struct str_hash{ size_t operator()(const string& str) const { return __stl_hash_string(str.c_str()); } }; struct str_equal{ bool operator()(const string& s1,const string& s2) const { return s1==s2; } }; int main(int argc, char *argv[]) { hash_map<string,string,str_hash,str_equal> mymap; mymap.insert(pair<string,string>("hcq","20")); mymap["sgx"]="24"; mymap["sb"]="23"; cout<<mymap["sb"]<<endl; if(mymap.find("hcq")!=mymap.end()) cout<<mymap["hcq"]<<endl; return 0; }

热点排行