1、字符串数字之间的转换
(1)string --> char * string str("OK"); char * p = str.c_str(); (2)char * -->string char *p = "OK"; string str(p); (3)char * -->CString char *p ="OK"; CString m_Str(p); //或者 CString m_Str; m_Str.Format("%s",p); (4)CString --> char * CString str("OK"); char * p = str.GetBuffer(0); ... str.ReleaseBuffer(); (5)string --> CString CString.Format("%s", string.c_str()); (6)CString --> string string s(CString.GetBuffer(0)); GetBuffer()后一定要ReleaseBuffer(),否则就没有释放缓冲区所占的空间,CString对象不能动态增长了。 (7)double/float->CString double data; CString.Format("%.2f",data); //保留2位小数 (8)CString->double CString s="123.12"; double d=atof(s); (9)string->double double d=atof(s.c_str());