I want to convert a string from char*
to wchar_t*
but that string is any language other than English for example (Russian, Chinese, Arabic, etc).
I have tried to do that by the following:
// This is just an example of conversion
const wchar_t * ToWide(const char* mbStr) {
const size_t cSize = mbstowcs(NULL, mbStr, 0) + 1;
wchar_t* wc = new wchar_t[cSize];
mbstowcs(wc, mbStr, cSize);
return wc;
}
int main() {
// just the first one is the only that works fine
wcout << ToWide("Hello"); // (English) The result: Hello
wcout << ToWide("Привет"); // (Russian) The result: ???????
wcout << ToWide("你好"); // (Chinese) The result: ??
wcout << ToWide("مرحبا"); // (Arabic) The result: ع╤═╚╟
}
Why did this happen and how can it be solved or what is the right way to convert from char* to wchar_t*?