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() 可以将字符串转化成整数,浮点数.
本文介绍了CString在MFC编程中如何转换为不同的字符类型,包括char*、LPCSTR及LPSTR的方法,并简单提及了atoi()和atof()函数的使用。
1176

被折叠的 条评论
为什么被折叠?



