1 #include <iostream>
2 #include <fstream>
3 #include <string>
4 #include <iomanip>
5 #include <vector>
6 #include <map>
7 #include <cctype>
8 #include <algorithm>
9 bool cmp(std::pair<std::string, size_t>& a,
10 std::pair<std::string, size_t>& b){
11 return a.second > b.second;
12 }//词频从大到小排序
13
14 int main(){
15 std::ifstream ifs{};
16 ifs.open("./input.txt", std::ifstream::in);//从input.txt读入文本
17 std::string text( (std::istreambuf_iterator<char>(ifs) ),
18 (std::istreambuf_iterator<char>() ) );
19 //std::istreambuf_iterator<char>()表示文件结尾
20 ifs.close();
21 const std::string separators{
" ():;.[],\n"};//分隔符,可自定义
22 std::map<std::string, size
【C++】统计文本词频程序
最新推荐文章于 2024-02-01 16:06:54 发布