C++中CString、char*、double之间的相互转换

C++中CString、char*、double之间的相互转换

CString<->char*

CString str_c;
char* str;

USES_CONVERSION; // 转换宏
str= T2A(str_c); //Cstring->str;

str_c="";
str_c+=str;      //str->Cstring;

double->char*/CString

CString str_c;
double data;
str_c.Format(_T("%f"),data); //double->CString

char* str;
sprintf(str,"%f",data);  //double-->char*

char*->double

char* str;
double data;
data=atof(str);

从Dlg中得到double值

double GetEditDouble(CDialogEx* dlg,UINT id)
{
	double data = 0;   //返回值
	CString str;      
	char* str1;
	dlg->GetDlgItemTextW(id, str);
	USES_CONVERSION; // 转换宏
	str1= T2A(str);
	data = atof(str1);
	return data;
}
posted @ 2021-06-08 23:27  CryCat  阅读(324)  评论(0编辑  收藏  举报