CString cstr = L"1";
CString转换为int i ;
i = _ttoi(cstr);
i = atoi((const char *)cstr);
i = atoi((char *)cstr);
//atoi、_atoi64或atol
CString转换为float f;
sscanf(str,"%f",&v);//float v;
double dVal = atof(LPCTSTR(str));
CString转换为string str;
string str(str.GetBuffer());//记得用str.ReleaseBuffer();释放空间
CString转换为char* ch;
ch=cstr.GetBuffer(cstr.GetLength());
ch=(LPCSTR)cstr;
ch = (char*)(LPCSTR)cstr;
ch = (char*)(LPCTSTR)cstr;
ch = (LPSTR)(LPCTSTR)cstr;
char* BasicFunction::StringToCharX(CString str)
{
int len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , NULL , 0 , NULL , NULL );
char* pAscii =new char[len+1];
len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , pAscii , len +1 , NULL ,NULL );
pAscii[len] = 0;
return pAscii;
}
CString转换成char[100] a;
strncpy(a,(LPCTSTR)cstr,sizeof(a));