map與set的使用

1, map的兩種遍歷

<span style="font-size:14px;">	map<string,int>::iterator it;
	for(it=MAP.begin();it!=MAP.end();++it){
		cout<<it->first<<" "<<it->second/100<<endl;
	}
	
	while(!MAP.empty()){
		cout<<(MAP.begin()).first<<(MAP.begin()).second<<endl;
		MAP.erase(MAP.begin());
	}</span>



2,set的插入

   set<int> s;

   s.insert(2);

set的遍歷

   set<int> ::iterator it;

   for(it=s.begin(); it!=s.end; it++)

      cout<<*it<<endl;





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章