int->CString: CString strInt; strInt.Format("%d",800); CString ->int: CString str("800"); int iNumber=atoi(LPCTSTR(str)); or: sscanf(LPCTSTR(str),"%d",&iNumber); or://one byte each time int len=str.GetLength(); int iNumber=0;//this is the resultfor(int i=0;i<len;i++){ if(str.GetAt(i)<'0'||str.GetAt(i)>'9') break; iNumber=iNumber*10+str.GetAt(i)-'0'; } //now u can deal with iNumber
int->CString: int iNumber=800; CString str; sprintf(str.GetBuffer(80),"%d",iNumber); str.ReleaseBuffer(); //now str was hold by "800"
CString string="800";
int i;
i=atoi(string);CString->int:
CString string;
string.Format("%d",800);
cstring=itoa("800")
CString string;
string.Format("%d",800);CString->int:
int n;
CString string="800";
n=atoi(string);
CString strtemp;
k=800;
// int to cstring
strtemp.format("%d",k);
//cstring to int
k=atoi(strtemp);
CString strInt;
strInt.Format("%d",800);
CString ->int:
CString str("800");
int iNumber=atoi(LPCTSTR(str));
or:
sscanf(LPCTSTR(str),"%d",&iNumber);
or://one byte each time
int len=str.GetLength();
int iNumber=0;//this is the resultfor(int i=0;i<len;i++){
if(str.GetAt(i)<'0'||str.GetAt(i)>'9') break;
iNumber=iNumber*10+str.GetAt(i)-'0';
}
//now u can deal with iNumber
int iNumber=800;
CString str;
sprintf(str.GetBuffer(80),"%d",iNumber);
str.ReleaseBuffer();
//now str was hold by "800"