我試圖建立從返回的方法的結果的Platform::String
const char*
C++/CX - 我需要從一個const char實例化一個平臺::字符串*
我根本無法得到這個工作,並多年來我一直在撓頭。
我不是一個非常有經驗的C++開發人員,所以答案可能很明顯,但我似乎無法解決。
感謝您的任何幫助。
我試圖建立從返回的方法的結果的Platform::String
const char*
C++/CX - 我需要從一個const char實例化一個平臺::字符串*
我根本無法得到這個工作,並多年來我一直在撓頭。
我不是一個非常有經驗的C++開發人員,所以答案可能很明顯,但我似乎無法解決。
感謝您的任何幫助。
Platform::String
內部使用char16
,並在其構造函數中使用char16*
。您需要使用MultiByteToWideChar
將char*
文本轉換爲char16*
文本。 This question談到從Platform::String
到char*
,並從char*
到Platform::String
應該遵循相反的路徑。
您可以使用mbstowcs http://www.cplusplus.com/reference/cstdlib/mbstowcs/填充wchar_t緩衝區,然後將其傳遞給Platform :: String構造函數以使用所需的數據創建實例。
static wchar_t buffer[ MAX_BUFFER ];
mbstowcs(buffer, source, MAX_BUFFER);
platformString = ref new Platform::String(buffer);