The problem is located in these lines:
const wchar_t* szText= convertedstring.c_str();
char *str = new char[1024];
sprintf(str,"%ls", szText);
Here you are converting the wide char string to multi byte using the current code page by using
sprintf
with the format
%ls
. All characters not supported by the current code page will not be shown later when printing the string.
Forget about using multi byte strings for user interaction nowadays. They are even converted back to wide strings when calling Windows API functions because Windows is using Unicode internally since nearly twenty years.
Your code is also much too complicated. If Out is a UTF-8 encoded
LPCSTR
or
LPSTR
:
int reqsize = ::MultiByteToWideChar(CP_UTF8, 0, Out, -1, NULL, 0);
if (reqsize > 0)
{
wchar_t *wide = new wchar_t[reqsize];
::MultiByteToWideChar(CP_UTF8, 0, Out, -1, wide, reqsize);
delete[] wide;
}