#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream file("1.3.4.txt"); // 假设输入文件名为input.txt
if (!file) {
cerr << "无法打开文件" << endl;
return 1;
}
string searchString = "your_search_string"; // 替换成你想搜索的字符串
string line;
int count = 0;
while (getline(file, line)) {
size_t pos = 0;
while ((pos = line.find(searchString, pos)) != string::npos) {
++count;
pos += searchString.length();
}
}
cout << "字符串 '" << searchString << "' 出现的频次: " << count << endl;
file.close();
return 0;
}
第三题3、编写一段程序,统计某个字符串在文本中出现的频次。
最新推荐文章于 2024-07-20 09:51:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)