我已经尝试将char *转换为wchar_t *,但我在使用mbstowcs时遇到了一些麻烦,Visual Studio需要mbstowcs_s ...
char *port;
size_t size = strlen(port) + 1;
wchar_t* portName = new wchar_t[size];
mbstowcs(portName, port, size);
如何将功能更改为mbstowcs_s?
答案 0 :(得分:27)
我不建议在使用安全方法的修复程序如此简单时禁用安全代码警告,所以请转到:
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;
在VS2013上使用cl /W3 /EHsc
进行了测试。