Reputation: 17544
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)
Upvotes: 0
Views: 1825
Reputation: 26975
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];
Upvotes: 3
Reputation: 62323
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.
Upvotes: 3