I stumbled upon this question while trying to understand why I get gibberish text when I convert PDF files into text, as part of
this [
^] project. This question is still relevant today, and there is no real answer. An ideal answer would be the same code blocked which was included in the original question, but fixed. So I did some research...
First, you need to use
imbue[
^] in order to set the encoding of your choice.
Second, use
wifstream [
^] instead of
ifstream[
^].
The following code works with
wstring[
^].
Note that some Visual Studio default projects contain
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
If so, remove this block. See
this answer about this Macro[
^].
So here is the fixed code:
#include <locale>
wstring OutputString;
wifstream IniFile (_T("D:\\FileName.INI"));
IniFile.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));
while (true )
{
getline(IniFile, OutputString);
}
Tested on my own project.
Before[
^]:
After[
^]: