提问人:gniewko milczarski 提问时间:10/18/2023 最后编辑:Remy Lebeaugniewko milczarski 更新时间:10/31/2023 访问量:91
UTF-8 字符未正确加载
UTF-8 characters not loading in properly
问:
我有一个学校项目,要求我加载一个包含 UTF-8 字符的文本文件,例如 ,然后对该文本进行一些编辑。"ł,ą,ż,ź,ć,..."
问题是,如果我使用 ,它会正确加载文件,但是如果我尝试使用 、 等,则字符会消失。SetConsoleOutputCP(65001)
cin
ł
ą
#include <iostream>
#include <fstream>
#include <string>
#include<windows.h>
using namespace std;
string opfile(string name){
string line;
ifstream myfile (name);
string tekst;
if (myfile.is_open())
{
while(getline(myfile, line)) {
tekst += line + "\n";
}
myfile.close();
}
else cout << "Unable to open file";
return tekst;
};
int main() {
SetConsoleOutputCP(65001);
string file_name;
cin >> file_name;
cout << opfile(file_name);
string cos;
cin >> cos;
cout << cos;
return 0;
}
这是文本文件中的内容
ŁŁŁŁŁŁŁŁĄĄĄĄĄĄĄĄĄĄĄÓÓÓÓĆÓŹŻÓŹĆŹŻÓĆŻÓźćÓÓÓĆŹÓŻĆŻÓŹĆÓŚĄŚĄÓÓĄŚÓŚĄÓÓŚÓŚĄ
如果我稍后尝试输入它,则不会输出任何内容。
我试着环顾四周,但每个人都说应该可以。SetConsoleOutputCP()
答: 暂无答案
评论
UTF-8
UTF-8
Utf-8