tr1::unordered_map demo

#include <tr1/unordered_map>
#include <string>
#include <iostream>
using namespace std;

/*
 * -std=c++0x
 */
int main(int argc, char** argv) {

    typedef tr1::unordered_map<std::string,std::string> HashStringType;
    HashStringType hashstring;
#if 1
    hashstring["hello"] = "world0";
    hashstring["hello1"] = "world1";
    hashstring["hello2"] = "world2";
    hashstring["hello3"] = "world3";
#endif  
#if 0  // not successful
    hashstring = {
        {"a123","a3243"},
        {"ad","a231" },
        {"as232","s231" },
    };
#endif
    // insert
   hashstring.insert(make_pair<string,string>("123","2323"));
   hashstring.insert(make_pair<string,string>("1a1223","2323"));
   typedef tr1::unordered_map<std::string,std::string>::iterator iterator_type;
   for( iterator_type it = hashstring.begin();it!= hashstring.end();++it)
   {
         std::cout<<it->first<<":"<<it->second.c_str()<<std::endl;
   }
   
   // hasher
  HashStringType::hasher fn = hashstring.hash_function();
  std::cout<<"hash(\"12342323\") = "<<fn("12342323")<<endl;
    
  // at  ---can't find 'at'
  //  hashstring.at("444444") = "555555";
 
  iterator_type it1 = hashstring.find("hello");
  if(it1!= hashstring.end())
  {
      cout<<"has found"<<endl;
  }
    
   
    return 0;
}

转载于:https://my.oschina.net/lyr/blog/112120

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值