0

How can I read a txt file that contains non-English strings? After getting the string I will store it in a linked list, so it should be suitable for storing in a node either, then print it.

When I try the get string "türkçe" from the .txt file code below, it gives the output of:

output: 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;
}
karel
  • 5,489
  • 46
  • 45
  • 50
  • 3
    Your problem is that the encoding of your console is different to the one of the file your are reading, and not that your are not able to store the content of your file in the string. – t.niese Mar 22 '19 at 05:51
  • 3
    Possible duplicate of [How can I print non English characters taken from a text file in c++?](https://stackoverflow.com/questions/47052373/how-can-i-print-non-english-characters-taken-from-a-text-file-in-c) – Varada Mar 22 '19 at 05:51

1 Answers1

0

The solution of the problem:

#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;
}
quarantina
  • 111
  • 7