I've faced an issue and couldn't find an answer on the internet. Even though I found many similar questions, none of the answers worked for me. I'm using Visual Studio 2015 on Windows 10.
So part of my code is:
wstring books[50];
wstring authors[50];
wstring genres[50];
wstring takenBy[50];
wstring additional;
bool taken[50];
_setmode(_fileno(stdout), _O_U8TEXT);
wifstream fd("bookList.txt");
i = 0;
while (!fd.eof())
{
getline(fd, books[i]);
getline(fd, authors[i]);
getline(fd, genres[i]);
getline(fd, takenBy[i]);
fd >> taken[i];
getline(fd, additional);
i++;
}
What I need, is to read a text file encoded in UTF-8 with C++. But, when I read the file, those wide strings are changed and when I print them, the output text is absolutely different.
Input:
ąčę
Output:
ÄÄÄ
How do I avoid it and read the text correctly?