本文主要是介绍C++ //练习 11.3 编写你自己的单词计数程序。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;
}
运行结果显示如下
这篇关于C++ //练习 11.3 编写你自己的单词计数程序。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!