I've tried convert a char* to wchar_t*, but I'm having some trouble using the mbstowcs and Visual Studio wants mbstowcs_s...
char *port;
size_t size = strlen(port) + 1;
wchar_t* portName = new wchar_t[size];
mbstowcs(portName, port, size);
How can I change the function to mbstowcs_s?
I wouldn't recommend disabling the secure code warnings when the fix to use the secure methods is so easy, so here you go:
const char *port="8080";
size_t size = strlen(port) + 1;
wchar_t* portName = new wchar_t[size];
size_t outSize;
mbstowcs_s(&outSize, portName, size, port, size-1);
std::wcout << portName << std::endl;
Tested with cl /W3 /EHsc
on VS2013.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With