C++ Primer(第5版) 练习 11.3
练习 11.3 编写你自己的单词计数程序。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
/*************************************************************************> File Name: ex11.3.cpp> Author: > Mail: > Created Time: Tue 02 Apr 2024 09:42:21 AM CST************************************************************************/#include<iostream>
#include<iomanip>
#include<string>
#include<map>
#include<vector>
using namespace std;int main(){map<string, size_t> wordCount;string word;cout<<"Enter words: ";while(cin>>word){++wordCount[word];if(cin.get() == '\n'){break;}}cout<<"Word Count: "<<endl;for(const auto &w : wordCount){cout<<"Word: "<<setw(8)<<left<<w.first<<" Count: "<<w.second<<endl;}return 0;
}