std::wstring widen(const std::string &in)
int len = MultiByteToWideChar(CP_UTF8, 0, &in, -1, NULL, 0);
std::wstring out(len, 0);
MultiByteToWideChar(CP_UTF8, 0, &in, -1, &out, len);
If you're asking will it work, probably. Is it correct?
MultiByteToWideCharat least the first time.
MultiByteToWideCharinvoked with a (-1) length, if successful, will include accounting for a zero-terminator (i.e. it will always return >= 1 on success). The length-constructor for
std::wstringdoes not require this.
std::wstring(5,0)will allocate space for six wide-chars; 5+zero-term. So technically you're allocating one-too-many wide-chars.
MultiByteToWideChar docs on
cbMultiByte and -1:
If this parameter is -1, the function processes the entire input string, including the terminating null character. Therefore, the resulting Unicode string has a terminating null character, and the length returned by the function includes this character.