[C++] map .first .second


#include <iostream>
#include <map>
using namespace std;
 
int main()
{
     map<string, int> words;
     for(string s; cin >> s;)
         ++words[s];
     for(const auto& p :words)
         cout << p.first << ": " << p.second << "\n";
}


 
The elements of a map<string,int> are of type pair<string,int>;
The first member of a pair is called first and the second member second.
 

发布了100 篇原创文章 · 获赞 175 · 访问量 54万+

猜你喜欢

转载自blog.csdn.net/f2006116/article/details/99187376