使用強制轉(zhuǎn)換。例如:
CString theString( "This is a test " );
LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString;
char *buf;
CString str = "hello ";
buf = (LPSTR)(LPCTSTR)str;
CString str = "ABC ";
char* chArr;
chArr = (char*)(LPCTSTR)str;
CString str( "50 ");
int nConv = atoi( str );
使用strcpy。例如:
CString theString( "This is a test " );
LPTSTR lpsz = new TCHAR[theString.GetLength()+1];
_tcscpy(lpsz, theString);
char szBuff[100];
CString str = "123456abc ";
strncpy( szBuff, str, strlen( str ) );
或
strncpy(szBuff, str, str.GetLength()); //不要+1了,防越界
使用CString::GetBuffer。例如:
CString s(_T( "This is a test "));
LPTSTR p = s.GetBuffer();
// 在這里添加使用p的代碼
if(p != NULL) *p = _T( '\0 ');
s.ReleaseBuffer();
// 使用完后及時釋放,以便能使用其它的CString成員函數(shù)
CString str( "this is a test! ");
char* szBuf = str.GetBuffer( str.GetLenghth() );
//......
str.ReleaseBuffer();
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。