I'm sure this question gets asked a lot but I just want to make sure there's not a better way to do this.
Basically, I have a const char* which points to a null-terminated C string. I have another function which expects a const wchar_t* pointing to a string with the same characters.
For the time being, I have been trying to do it like this:
size_t newsize = strlen(myCString) + 1;
wchar_t * wcstring = new wchar_t[newsize];
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wcstring, newsize, myCString, _TRUNCATE);
delete[] wcstring;
I need to make these conversions in a lot of places since I'm dealing with 3rd party libraries which expect one or the other. Is this the recommended way to go about this?