4530: 【例】map-使用-1
内存限制:128 MB
时间限制:1.000 S
评测方式:文本比较
命题人:
提交:12
解决:12
题目描述

提示
#include<bits/stdc++.h> using namespace std; int main(){ //1、定义一个 map,默认根据 key 升序排序 map<int,string> m; //为map 元素赋值 m[1000]="Zhang"; m[1002]="Zhao"; m[1003]="Sun"; m[1001]="Wang"; m[1000]="Li"; //2、获取键(关键字 key)为 1000 的值 cout<<m[1000]<<endl; map<int,string>::iterator it; //遍历 map for(it =m.begin();it != m.end();it++){ cout<<it->first<<" "<<it->second<<endl; } return 0; }