如何读取包含非英语字符串的TXT文件?获得字符串后,我将其存储在链接列表中,因此它应该适合存储在节点中,然后打印。
当我从下面的.txt文件代码中尝试get字符串"türkçe"时,它给出了:
的输出输出:tⁿrkτe
**word.txt**
türkçe
<string>
<iostream>
<fstream>
int main() {
fstream inputFile;
inputFile.open(word.txt);
string line;
getline(inputFile,line);
cout << line << endl;
return 0;
}
问题的解决方案:
#include <string>
#include <iostream>
#include <fstream>
#include <locale.h>
using namespace std;
int main() {
setlocale(LC_ALL, "turkish");
fstream inputFile;
inputFile.open("word.txt");
string line;
getline(inputFile,line);
cout << line << endl;
return 0;
}