每一个map的对象是pair类型,pair含有first和second对象用以访问pair的key与value
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(void) {
map<string, int>_map;
string a; int b;
while (cin>>a) {
pair<string, int> _pair = make_pair(a, 1);
auto iter = _map.insert(_pair);
//cout<<iter.first->first<<" "<<iter.first->second<<endl;
}
for (map<string, int>::iterator ix = _map.begin(); ix != _map.end(); ix++)
cout << ix->first << " " << ix->second << endl;
system("pause");
return 0;
}