STL/map的遍历和初始化方式
来源:互联网 发布:淘宝客好做吗 编辑:程序博客网 时间:2024/06/03 23:54
/*
第一种
m.insert(pair<string,int> ("a",1));
m.insert(pair<string,int> ("b",2));
m.insert(pair<string,int> ("c",3));
第二种
m.insert(map<string,int>::value_type("a",1));
m.insert(map<string,int>::value_type("b",2));
m.insert(map<string,int>::value_type("c",3));
第三种
m["a"]=1;
m["b"]=2;
m["c"]=3;
m["b"]=2;
m["c"]=3;
注意的是<>里卖弄的类型变量是可以修改的m[1]="a";
*/
//遍历map俩民的元素
#include<map>
#include<string>
#include<iostream>
using namespace std;
int main()
{
map<string,int> m;
m["a"]=1;
m["b"]=2;
m["c"]=3;
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();++it)
cout<<"key: "<<it->first <<" value: "<<it->second<<endl;
return 0;
}
#include<string>
#include<iostream>
using namespace std;
int main()
{
}
map<string,int>::iterator it; 定义一个迭代指针it。
it->first 为索引键值,it->second 为值。
阅读全文
0 0
- STL/map的遍历和初始化方式
- map 的初始化和遍历
- stl map遍历和删除的方法
- 另一种遍历Map的方式: Map.Entry 和 Map.entrySet()
- 另一种遍历Map的方式: Map.Entry 和 Map.entrySet()
- 另一种遍历Map的方式 Map.Entry 和 Map.entrySet()
- 另一种遍历Map的方式: Map.Entry 和 Map.entrySet()
- 另一种遍历Map的方式: Map.Entry 和 Map.entrySet()
- List 和Map的遍历方式
- HasgMap和Map的遍历方式
- Map的遍历方式
- Map的遍历方式
- 遍历Map的方式
- map的遍历方式
- Map的遍历方式
- 遍历Map的方式
- Map的遍历方式
- Map的遍历方式
- sed命令
- 文件管理
- Redis学习笔记——初级
- 类和对象
- Hdu5748-Bellovin-最长上升子序列(LIS)
- STL/map的遍历和初始化方式
- C++ copy()函数
- JavaScript闭包详解
- vux中scroller插件,不好发现的神技巧
- PHP环境搭建和编写API接口
- Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled解决办法
- 51nod 1005 大数加法
- 如何理解项目沟通管理
- Hive on Spark调优