1

The file is UTF-8 (65001) encoded. I can't read cyrillic symbols from it.

CString FNAME;
CStdiofile fNFR;

fNFR.Open(_T("LFS200.25"), CFile::modeRead);
fNFR.ReadString(FNAME);

And got this:

 Зимний максимум 1989/90 гг.

instead of this:

 Зимний максимум 1989/90 гг.

Tried

setlocale(LC_ALL, "Rus");

Still the same problem.

How to get proper string?

Nika_Rika
  • 613
  • 2
  • 6
  • 29
  • 1
    This *is* UTF8. C++ has 16-bit characters (char16_t) and strings but UTF8 strings are treated as char. If you want to convert the UTF8 bytes to UTF16 you need codecvt – Panagiotis Kanavos Feb 08 '17 at 11:56
  • 1
    Check [this question on UTF support in C++](http://stackoverflow.com/questions/6796157/unicode-encoding-for-string-literals-in-c11) and the [String and Character Literals](https://msdn.microsoft.com/en-us/library/69ze775t.aspx) page in MSDN – Panagiotis Kanavos Feb 08 '17 at 11:59
  • 1
    Check [codecvt_utf8_utf16](http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16). You should be able to convert your UTF8 string to UTF16 with `std::u16string u16_conv = std::wstring_convert< std::codecvt_utf8_utf16, char16_t>{}.from_bytes(u8);` – Panagiotis Kanavos Feb 08 '17 at 12:10

1 Answers1

0

I found the answer here (need to convert utf-8 to utf-16):

CONVERSION BETWEEN UNICODE UTF-16 AND UTF-8 IN C++/WIN32

Nika_Rika
  • 613
  • 2
  • 6
  • 29
  • That's *not* a good solution. It was written 7 years ago, when C++ didn't have native Unicode support. In the end, it's just a call to `WideCharToMultiByte`. I'm 100% certain that the author would tell you today "Don't do this!". – Panagiotis Kanavos Feb 08 '17 at 13:44
  • 1
    Or [initialize CStdioFile with a UTF8 FILE stream](http://stackoverflow.com/a/17378096/134204) – Panagiotis Kanavos Feb 08 '17 at 13:46