#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<map>
using namespace std;
int main() {
wifstream ifs;
vector<wchar_t>text;//存储文章
map<wchar_t, int>all;
map<wchar_t, int>::iterator p;
ifs.open("附件.txt", ios::in);
if (!ifs.is_open()) {
cout << "文件打开失败" << endl;
return -1;
}
int times = 0;
wchar_t c;
while (ifs.get(c)) {
text.push_back(c);
}
for (int i = 0; i < text.size(); i++) {
for (int n = 0; n < text.size(); n++) {
if (text[i] >= 128) {//判定是否为中文字符
if (text[i] == text[n]) {
times++;
}
}
}
all[text[i]] = times;//将中文字符及出现的频次保存在map中
wcout << text[i];//输出文章
times = 0;
}
system("pause");
for (p = all.begin(); p != all.end(); p++) {
wcout << p->first << ":" << p->second << endl;//输出map中的汉字及其出现的次数
}
ifs.close();
return 0;
}
为什么这个代码输出map中的汉字及其出现的次数这个部分在控制台上是乱码?是哪里有出错嘛,真心求解了
