map基本用法

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<iostream>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 #include<stack>
10 #include<string>
11 #include<algorithm>
12 #define maxn +50
13 #define inf 0x7fffffff
14 #define xiao 1e-9
15 using namespace std;
16 map <string,int> ma;
17 int main()
18 {
19 ma["pear"];
20 ma["apple"]=1;
21 ma["banana"]=2;
22 ma["lemon"]=3;
23 cout<<ma.size()<<endl;
24 cout<<ma["apple"]<<endl;
25 if(ma.count("pear")) cout<<"pear"<<endl;
26 else cout<<"no pear"<<endl;
27 cout<<ma.lower_bound("cow")->first<<endl;
28 cout<<ma.lower_bound("cow")->second<<endl;
29 cout<<ma.begin()->first<<endl; 
30 cout<<ma.end()->second<<endl;//这个函数似乎并没有什么卵用 
31 return 0;
32 }
原文地址:https://www.cnblogs.com/TYH-TYH/p/4930202.html