C++ STL Map使用
来源:互联网 发布:苹果电影制作软件 编辑:程序博客网 时间:2024/06/11 13:54
第一种:用insert函数插入pair数据
#include <map>#include <string>#include <iostream>using namespace std;int main(){map<int,string> mapStudent; mapStudent.insert(pair<int, string>(1,"student_one")); mapStudent.insert(pair<int, string>(2,"student_two")); mapStudent.insert(pair<int, string>(3,"student_three")); map<int, string>::iterator iter; for(iter=mapStudent.begin();iter!= mapStudent.end();iter++){ cout<<iter->first<<" "<<iter->second<<endl;}return 0;}
第二种:用insert函数插入value_type数据
#include <map>#include <string>#include <iostream>using namespace std;int main(){map<int,string> mapStudent; mapStudent.insert(map<int, string>::value_type (1,"student_one")); mapStudent.insert(map<int, string>::value_type (2,"student_two")); mapStudent.insert(map<int, string>::value_type (3,"student_three")); map<int, string>::iterator iter; for(iter=mapStudent.begin();iter!= mapStudent.end();iter++){ cout<<iter->first<<" "<<iter->second<<endl;}return 0;}
第三种:用数组方式插入数据
#include <map>#include <string>#include <iostream>using namespace std;int main(){map<int,string> mapStudent; mapStudent[1]="student_one"; mapStudent[2]="student_two"; mapStudent[3]="student_three"; map<int, string>::iterator iter; for(iter=mapStudent.begin();iter!= mapStudent.end();iter++){ cout<<iter->first<<" "<<iter->second<<endl;}return 0;}
真正有用的是下面的根据关键字查找(字符串类型)其他信息
#include <map>#include <string>#include <iostream>using namespace std;int main(){map<string,string>mapStudent; /* mapStudent.insert(map<string, string>::value_type ("zhangsan","student_one")); mapStudent.insert(map<string, string>::value_type ("lisi","student_two")); mapStudent.insert(map<string, string>::value_type ("wangwu","student_three"));*/mapStudent["zhangsan"]="bad boy";mapStudent["lisi"]="good boy";mapStudent["wangwu"]="good girl"; map<string,string>::iterator iter; iter=mapStudent.find("lisi"); if(iter!=mapStudent.end()) cout<<iter->first<<":"<<iter->second<<endl; iter=mapStudent.find("tianqi"); if(iter==mapStudent.end()) cout<<"There is no such a man"<<endl;return 0;}
- c++stl map数组下标的使用
- [C++][STL][map]C++ map的基本操作和使用
- [c++]stl map
- C++STL:map概述
- C++stl map学习
- C++STL之map
- 【C++】STL--MAP
- [C++]STL之map
- C++STL 之map
- C++STL之map
- STL map使用详解
- STL map使用
- STL Map使用示例
- STL map使用
- C++ STL Map使用
- stl 复习:map使用
- STL中map使用
- stl::map使用小结
- 指针总结
- 【ios】2个viewController之间传值(segue方式)
- 一,软件工程的概论
- 创新工场笔试题2013年校园招聘
- GIT
- C++ STL Map使用
- 由于浏览器版本造成的HttpServlet获取request请求对象中含中文乱码问题
- 程序员必读经典书籍
- Unicode与UTF-8互转(C语言实现)
- 如何控制datagrid里编辑功能出现的TextBox的宽度,传递DataGrid中的值,如何用程序隐藏和显示DataGrid中的一列
- JAVA反射机制的学习
- 没有return false导致锚点跳转失效
- gcc使用
- CF 79D. Password