C++: Conversion between different kinds of string

Adopt from

http://msdn.microsoft.com/en-us/library/ms235631(vs.80).aspx


CString to char*

CString orig("Hello, World!");
wcout << orig << " (CString)" << endl;

// Convert to a char*
const size_t newsize = 100;
char nstring[newsize];
strcpy_s(nstring, orig);

char * to CString

char *orig = "Hello, World!";
cout << orig << " (char *)" << endl;

// Convert to a CString
CString cstring(orig);
cstring += " (CString)";
cout << cstring << endl;

本篇發表於 C, C++ 並標籤為 , , 。將永久鏈結加入書籤。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *