1、CString to char* :
CString cStr = "Hello,world!";
char* zStr = (char*)(LPCTSTR)cStr;
2、CString to LPCSTR
将CString转换成LPCSTR,需要获得CString的长度,例如:
CString cStr = _T("Hello,world!");
int nLen = cStr.GetLength();
LPCSTR lpszBuf = cStr.GetBuffer(nLen);
3、CString to LPSTR
这个和第3个技巧是一样的,例如:
CString cStr = _T("Hello,world!");
int nLen = str.GetLength();
LPSTR lpszBuf = str.GetBuffer(nLen);
atoi(), atof() 可以将字符串转化成整数,浮点数.
CString cStr = "Hello,world!";
char* zStr = (char*)(LPCTSTR)cStr;
2、CString to LPCSTR
将CString转换成LPCSTR,需要获得CString的长度,例如:
CString cStr = _T("Hello,world!");
int nLen = cStr.GetLength();
LPCSTR lpszBuf = cStr.GetBuffer(nLen);
3、CString to LPSTR
这个和第3个技巧是一样的,例如:
CString cStr = _T("Hello,world!");
int nLen = str.GetLength();
LPSTR lpszBuf = str.GetBuffer(nLen);
atoi(), atof() 可以将字符串转化成整数,浮点数.