hash_map自学笔记
来源:互联网 发布:运营商网络转型 编辑:程序博客网 时间:2024/06/03 14:24
只是一个简单的例程,使用stlport5.21
#include <hash_map>
#include <iostream>
using namespace std;
template<class Key,class NameType,class YearType,class Addrtype>
struct StudentRecord_tag{
struct StudentInfo_tag{
NameType name;
YearType year;
Addrtype addr;
};
typedef Key IdType;
typedef StudentInfo_tag StudentInfo;
IdType id;
StudentInfo sf;
};
int main()
{
hash_map<const char*,float> hm;
hm["orange"]=3.45f;
hm["lichee"]=5.67f;
hm["banana"]=3.89f;
cout<<hm["banana"]<<endl;
hm.erase("lichee");
pair<const char*,float> p("pear",8.9f);
hm.insert(p);
hash_map<const char*,float>::iterator i,iend;
iend=hm.end();
for (i=hm.begin();i!=iend;i++)
{
cout<<(*i).first<<" "<<(*i).second<<endl;
}
cout<<hm.bucket_count()<<endl;
cout<<hm.size()<<endl;
cout<<endl;
typedef StudentRecord_tag<int,char*,int,char*> StudentRecord;
StudentRecord sr[]={
{192,"李强",28,"武汉"},
{168,"月月",34,"广州"},
{123,"王青",54,"成都"}
};
hash_map<StudentRecord::IdType,StudentRecord::StudentInfo> hms;
for (int j=0;j<3;j++)
{
hms[sr[j].id]=sr[j].sf;
}
hash_map<StudentRecord::IdType,StudentRecord::StudentInfo>::iterator ii,iiend;
iiend=hms.end();
for (ii=hms.begin();ii!=iiend;ii++)
{
cout<<(*ii).first<<" "
<<(*ii).second.name<<" "
<<(*ii).second.year<<" "
<<(*ii).second.addr<<endl;
}
cout<<endl;
ii=hms.find(192);
if (ii!=iiend)
{
cout<<(*ii).first<<" "
<<(*ii).second.name<<" "
<<(*ii).second.year<<" "
<<(*ii).second.addr<<endl;
}
else
{
cout<<"failed!"<<endl;
}
system("PAUSE");
return 0;
}
- hash_map自学笔记
- C++笔记:STL扩展hash_map
- 自学笔记
- hash_map
- hash_map
- hash_map
- hash_map
- hash_map
- hash_map
- hash_map
- HASH_MAP
- hash_map
- hash_map
- hash_map
- hash_map
- hash_map
- hash_map
- hash_map
- .net 常用命名空间
- linux块设备驱动
- 使用CSS时的DOCTYPE选择
- 6.15判断数独
- vb6,vs2005快捷键_排序算法的稳定性
- hash_map自学笔记
- 蓝桥杯 求自然数序列的最小公倍数
- 有一天我也会老去(写在2013年父亲节)
- JAVA IO 设计模式彻底分析
- Embed使用以及九宫格的用法
- android自定义控件
- 在线帮助你修改图片背景的工具 - Clipping Magic
- 信号量semaphore
- c++简单程序设计(一)