C++ STL容器之map

在這裏插入圖片描述在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

#include <iostream>
#include <string>
#include<map>
using namespace std;
int main()
{    
	map <string,int>dict;//創建map   將string 映射爲整形 
	dict["Tom"]=1;  //往map裏面插入元素  
	dict["jane"]=2;
	dict["mary"]=1;
	if(dict.count("marry"))//查詢是否有marry .有返回一,無返回零  
    {
	cout<<"marry is in class"<<dict["mary"];
	 }
	 for(map<string,int>::iterator it =dict.begin();it!=dict.end();it++)
	 {
	 	cout<<it->first<<" is in class"<<it->second<<endl;  //輸出第一個元素,輸出第二個元素。 
		}
		 return 0;	
 } 

在這裏插入圖片描述

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