c++ hash

您所在的位置:网站首页 map常用函数 c++ hash

c++ hash

#c++ hash| 来源: 网络整理| 查看: 265

c++ STL库里有自定义的hash_map 方法,但是使用起来并不是那么方便

hash_map主要的方法有

find(),insert()

我结合官方API说明一下他们的用法

一、需要特别注意的地方,

1.头文件的引用

2.如何插入一个键值对(参考一下代码)

3.find()的返回值

4.如何获取某一个key值相应的value值

 hm1_RcIter -> second 分别用。first,和,second,指代key和value的值 // hash_map_find.cpp // compile with: /EHsc #define _DEFINE_DEPRECATED_HASH_CLASSES 0 #include #include int main( ) {    using namespace std;    using namespace stdext;    hash_map hm1;    hash_map :: const_iterator hm1_AcIter, hm1_RcIter;    typedef pair Int_Pair;    hm1.insert ( Int_Pair ( 1, 10 ) );    hm1.insert ( Int_Pair ( 2, 20 ) );    hm1.insert ( Int_Pair ( 3, 30 ) );    hm1_RcIter = hm1.find( 2 );    cout     {         size_t operator()( const std::string& x ) const         {             return hash< const char* >()( x.c_str() );         }     };     template struct hash     {         size_t operator()(long long x) const         {             return x;         }     }; }

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3