#include <iostream>
#include <fstream>
#include <map>
int main() {
std::string filename = "example.txt"; // 替换为你要统计的txt文件路径
std::ifstream file(filename);
if (!file.is_open()) {
std::cout << "无法打开文件" << std::endl;
return 0;
}
std::map<char, int> charCount;
char c;
while (file.get(c)) {
if (std::isalpha(c)) { // 只统计字母字符
charCount[c]++;
}
}
file.close();
// 输出字符及其出现次数
for (const auto& pair : charCount) {
std::cout << "'" << pair.first << "': " << pair.second << std::endl;
}
return 0;
}