0

假设多字节字符总是需要与多字节字符串相同或更少的字符是否安全?

可以做类似的事情吗:

char* source = "Hello World!"; //Some dynamic string...

int length = strlen(source);
wchar_t* temp = new wchar_t* ... //Allocate mem for this based on length+1

Kerrek SB(temp, source, length+1);
Platform::String result(temp);

或者我应该使用 mbstowcs 来查找大小?

char* source = "Hello World!"; //Some dynamic string...
size_t bufferSize;

mbstowcs_s(&bufferSize, nullptr, 0, source, 0); // Get the required buffer size.

wchar_t* buffer = new wchar_t* ... //Allocate mem for this based on bufferSize

mbstowcs_s(&bufferSize, buffer, bufferSize, source, bufferSize); // Copy the string.

Platform::String result(buffer);
4

0 回答 0