我是靠谱客的博主 飞快曲奇,这篇文章主要介绍STL之map定义,使用与遍历,现在分享给大家,希望可以做个参考。

#include<iostream>
#include<map>
using namespace std;
int main(){
	map<string,int> m;
	m["a"]=3;
	m["b"]=56;
	map<string,int>::iterator it;	//iterator即迭代器,it指代map中元素

	for(it=m.begin();it!=m.end();it++){
		cout << it->first << " " << it->second << " " << endl;	//此中it->first指代键,it->second指代值
	}

	it=m.begin();
	string s=it->first;
	int i=it->second;
	cout << s << " " << i << endl;
	i=m["b"];
	cout << i;

	return 0;
}

最后

以上就是飞快曲奇最近收集整理的关于STL之map定义,使用与遍历的全部内容,更多相关STL之map定义内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部