关联式容器映射map练习
来源:互联网 发布:项尖数据恢复注册码 编辑:程序博客网 时间:2024/06/05 16:58
//管理学生名册
#include <iostream>
#include <map>
#include <string>
using namespace std;
struct student
{
string id;
string name;
int grade;
};
int main()
{
map<string,student> stubook;
student stu;
cout<<"--creat student book--"<<endl;
for(int i=0;i<2;i++)
{
cin>>stu.id;
cin>>stu.name;
cin>>stu.grade;
stubook[stu.id]=stu;
}
//判断student book是否为空
if(stubook.empty()) cout<<"stubook is empty!"<<endl;
else cout<<"stubook isnot empty!"<<stubook.size()<<endl;
//输出student book
cout<<"---print student book--"<<endl;
map<string,student>::iterator iter=stubook.begin();
for( ;iter!=stubook.end();iter++)
{
cout<<"student book:"<<iter->second.id<<" - "<<iter->second.name<<" -"<<iter->second.grade<<endl;
}
//查找学生
cout<<"---find a student(please input studentid)--"<<endl;
string studentid;
cin>>studentid;
iter=stubook.find(studentid);
if(iter==stubook.end())
{
cout<<"cannot find: "<<studentid<<endl;
}
else
{
cout<<"student: "<<iter->second.id<<" - "<<iter->second.name<<" - "<<iter->second.grade<<endl;
cout<<"do you want to delete the student (y/n):"<<endl;
char c;
cin>>c;
if(c=='y')
{
stubook.erase(studentid);
}
}
//输出student book
cout<<"---print student book--"<<endl;
map<string,student>::iterator iter2=stubook.begin();
for( ;iter2!=stubook.end();iter2++)
{
cout<<"student book:"<<iter2->second.id<<" - "<<iter2->second.name<<" -"<<iter2->second.grade<<endl;
}
return 0;
}
- 关联式容器映射map练习
- STL关联式容器之映射表——map
- linux下练习 c++ 关联式容器map特性
- 关联容器,集合set和映射map
- 关联式容器-map
- 关联式容器map/multimap
- STL容器-关联式容器map/multimap
- 【STL】容器 > 关联式容器 > map
- C++容器---关联式容器<map>&<multimap>
- map——关联式容器
- 关联式容器set和map原理
- 关联式容器:set和map
- SGISTL源码探究-关联式容器:map
- STL::map关联容器
- C++ 关联容器 map
- 关联容器Map
- ACE 关联容器 MAP
- C++MAP关联容器
- linux基础学习(1)
- 迎接2017
- 恐龙技术生存体验(五 峰回路转)
- 代理模式与动态代理模式
- 中兴手机权限开启方法3
- 关联式容器映射map练习
- 四、servlet 分页加载技术
- SPOJ - Horace and his primes(素数+二分查找)
- Error: Error parsing D:\new_android\Android SDK\system-images\android-25\android-wear\armeabi-v7a\de
- C++文件练习
- c#中,类的重写中,new和override的区别
- GIS就业参考系列之方向篇——条条大道通罗马
- ffmpeg 不能发送60帧视频问题分析
- 项目实践---字典