- 從char*轉換:
char *chars = "Hello";
- 從char*到string: string s(chars);
- 從char*到CString: CString s(chars);
- 從char*到String^: String ^s = gcnew String(chars);
- 從string轉換
string str("Hello");
- 從string到char*: char chars[64]; strcpy_s(chars, str.c_str());
- 從string到CString: CString s(str.c_str());
- 從string到String^: String ^s = gcnew String(str.c_str());
- 從CString轉換
CString str("Hello");
- 從CString到char*: char chars[64]; strcpy_s(chars, str);
- 從CString到string: string s(str);
- 從CString到String^: String ^s = gcnew String(str);
- 從String^轉換
CString str("Hello");
pin_ptr<const wchar_t> wch = PtrToStringChars(str);
1.從String^ 到char*:
char chars[64];
size_t convertedChars = 0;
wcstombs_s(&convertedChars, chars, wcslen(wch) + 1, wch, _TRUNCATE);
2.從String^ 到string:
string s(wch);
3.從String^ 到CString:
String ^s = gcnew String(wch);