Unable to convert CStringW to CStringA

I am working on a single project where I applied one conversion problem CStringWin CStringAfor a multibyte string such as Japanese.

I load a string from string resources using a method LoadString(). I tried the following code but it does not work.

CStringW csTest;
csTest.LoadString(JAPANESE_STRING);
CStringA Msg = CStringA(csTest); // Msg has been returned blank string

AND

std::string Msg = CW2A(csTest);// Msg has been returned blank string

I also tried wcstombs()too.

Can someone tell me how I can convert CStringWto CString? Thanks in advance.

+4
source share
1 answer

CStringWstores Unicode UTF-16 strings .

What encoding do you expect for yours CStringA?

UTF-8?
:

// strUtf16 is a CStringW.
// Convert from UTF-16 to UTF-8
CStringA strUtf8 = CW2A(strUtf16, CP_UTF8);

CStringA .

CW2A - , WideCharToMultiByte() API Win32 CodePage ( , CW2A ++ RAII API). API, ( ).

+5

Source: https://habr.com/ru/post/1528923/


All Articles