views:

141

answers:

2

In my code, I receive a const char array like the following:

const char * myString = someFunction();

Now I want to postprocess it as a wchar array since the functions I use afterwards don't handle narrow strings.

What is the easiest way to accomplish this goal?

Eventually MultiByteToWideChar? (However, since it is a narrow string which I get as input, it doesn't have multibyte characters => probably not the most beautiful solution)

+3  A: 

MultiByteToWideChar will work unless you are using extended characters in your narrow string. If its a plain alpha numeric string then it should work fine.

you can also look at mbstowcs which is a little less convoluted but doesn't offer the same amount of control.

Goz
+2  A: 
const char * myString = someFunction();
const int len = strlen(myString);
std::vector<wchar_t> myWString (len);
std::copy(myString, myString + len, myWString.begin());
const wchar_t * result = &myWString[0];
Alexey Malistov