15,978
社区成员




double PI = 3.14;
char ch[100];
sprintf(ch, "%lf", PI);
MessageBoxA(NULL, ch, "PI", 0);
记得包含stdio.h
如果编译不通过,提示安全问题,请参考
http://blog.csdn.net/weixin_39449570/article/details/78801573
// W32Cstring.cpp : Defines the entry point for the application.
//
#include <afxwin.h> // MFC core and standard components
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
CString str;
double PI=3.14;
str.Format("%f",PI);
MessageBox(NULL, str, TEXT("PI"), 0);
return 0;
}
1 因为 没有 stdafx.h 所以 “Setting“ 中 ,不要 使用 预编译头 ! 但 “General” 中 要 使用 Use MFC
2 CString 在<afx.h> 中。已包含 <windows.h>
3 所以 不要 #include <windows.h>