I’ve tried implementing a function like this, but unfortunately it doesn’t work:
const wchar_t *GetWC(const char *c)
{
const size_t cSize = strlen(c)+1;
wchar_t wc[cSize];
mbstowcs (wc, c, cSize);
return wc;
}
My main goal here is to be able to integrate normal char strings in a Unicode application. Any advice you guys can offer is greatly appreciated.
Use a
std::wstringinstead of a C99 variable length array. The current standard guarantees a contiguous buffer forstd::basic_string. E.g.,C++ does not support C99 variable length arrays, and so if you compiled your code as pure C++, it would not even compile.
With that change your function return type should also be
std::wstring.Remember to set relevant locale in
main.E.g.,
setlocale( LC_ALL, "" ).