1.CString->int、long
CString strTest = "1000 test";
int i = 0;
i = _ttoi(strTest);
strTest = "-199 dollars";
long l = 0;
l = _ttol(strTest);
输出:
i = 1000;
l = -199;
2.CString<->char*
2.1 char*->CString
char* psz = "Test";
CString str(psz);
CString str = psz;
2.2 CString->char*
2.2.1 使用强制类型转换将CString转为LPCTSTR
CString str("Test");
LPCTSTR pStr = str;
2.2.2 使用CString的GetBuffer函数,在使用CString对象的其他的任何成员之前必须调用ReleaseBuffer释放缓冲区。
CString str("Test");
LPCTSTR pStr = str.GetBuffer(0);
// 直接访问CString的缓冲区
char* psz = NULL;
strcpy(psz , "Hello");
str.ReleaseBuffer();
2.2.3 强制将CString转换为LPTSTR
CString str("Test");
LPTSTR pStr = (LPTSTR)(LPCTSTR)str;