Home > Software engineering >  How can I MessageBox display value of a variable
How can I MessageBox display value of a variable

Time:09-24

# include & lt; Windows. H>
Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
Double PI=3.14
MessageBox (NULL, TEXT (PI), TEXT (" PI "), 0).
return 0;
}

There are many online, have said is very simple, using cstrings transformation, opinions vary, all cannot come true, all say so it is feasible, but how cstrings statement definition is a hard, just with & lt; Windows. H> Conflict, if the operation, help solve once,
CString str;
STR. The Format (" % d ", S * 4/100);
MessageBox (NULL, TEXT (STR), TEXT (" PI "), 0).

CodePudding user response:

Prompt what mistake? Above

CodePudding user response:

The integer or floating point number into a string to display

CodePudding user response:

 
Double PI=3.14;
TCHAR ch [100].
_stprintf (ch, TEXT (" % lf "), PI);
MessageBox (NULL, ch, TEXT (" PI "), 0).


If is an integer string with % d, % u

CodePudding user response:

Yi, my 3rd floor,, if you are not new MFC project, but the win32 console application, at the time of using messageBOX may need to add a macro 'L'

CodePudding user response:

Not ah, prompt undefined identifiers "_stprintf
"I am not new MFC project, it is a simple win32 program, I am a beginner, the original is playing console, now want to transplant a few small things to MessageBox, what also don't succeed, is simple in theory, to put the Numbers into a character, and also is the wide character,


reference 4 floor paschen response:
 
Double PI=3.14;
TCHAR ch [100].
_stprintf (ch, TEXT (" % lf "), PI);
MessageBox (NULL, ch, TEXT (" PI "), 0).


If is an integer string with % d, % u

CodePudding user response:

There are countless people said into cstrings then Messagebox

Too lean,
CString str;
STR. The Format (" % d ", PI);
MessageBox (NULL, STR, TEXT (" PI "), 0). Pass it, of actual cstrings undefined, this definition is quite troublesome, there is a definition file, write, tips and Windows. H conflict, the code is very simple, is a small example, trouble expert help help home, come to a complete code, declaration definition file how to define,

CodePudding user response:

refer to 6th floor tanes response:
not ah, prompt undefined identifiers "_stprintf
"I am not new MFC project, it is a simple win32 program, I am a beginner, the original is playing console, now want to transplant a few small things to MessageBox, what also don't succeed, is simple in theory, to put the Numbers into a character, and also is the wide character,


Quote: refer to 4th floor paschen response:

 
Double PI=3.14;
TCHAR ch [100].
_stprintf (ch, TEXT (" % lf "), PI);
MessageBox (NULL, ch, TEXT (" PI "), 0).


If it is integer string with % d, % u

Contains tchar. H header file

CodePudding user response:

It doesn't have to be using cstrings like you upstairs said, you can
WCHAR MSG []=L "How you!" ;
MessageBox (NULL, MSG, L "Hello", 0).
Want to use the format to use sprintf or sprintfs_s

CodePudding user response:

references 9 f qq_39850605 response:
doesn't have to use cstrings upstairs just like you said, you can
WCHAR MSG []=L "How you!" ;
MessageBox (NULL, MSG, L "Hello", 0).
Want to use the format to use sprintf or sprintfs_s


To put it bluntly, I am going to put a double number, displayed on the message,

CodePudding user response:

# include & lt; Windows. H>
Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
WCHAR szBuffer [100].
Double number=3.14;
Wsprintf (szBuffer, L % lf, number).
MessageBox (NULL, szBuffer, TEXT (" format string "), 0).
}

I improved, int type % d, can pass, with double, % lf output only a f, % f output only a f

CodePudding user response:

More often than not, check the function return value judgment reason

http://en.cppreference.com/w/c/io/fprintf

Of course you also can realize:

http://blog.csdn.net/paschen/article/details/74554955

CodePudding user response:

You can also use GCVT realize turn string floating point number

CodePudding user response:

 
//W32Cstring. CPP: Defines the entry point for the application. The
//

# include & lt; 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. The Format (" % f ", PI);
MessageBox (NULL, STR, TEXT (" PI "), 0).
return 0;
}

1 because no stdafx. H "Setting", so don't use the precompiled header! But in the "General" to Use the Use MFC
2 cstrings in & lt; Afx. H> Already included, & lt; Windows. H>
3 therefore do not # include & lt; Windows. H>

CodePudding user response:

Double PI=3.1415926;
STR. The Format (" % 8.7 f ", PI);
Output:
3.1415926

CodePudding user response:

Can not & lt; Afxwin. H> But & lt; Afx. H>

CodePudding user response:

1 the include & lt; Ctype> The atoi ()
Low itoa () : converts integer value to a string,
Low ltoa () : converts a long integer value to a string
2 the string. Format
In addition, if it is easy language, to the text (),

CodePudding user response:

If you don't want to deal with wide character problem, please use MessageBoxA

CodePudding user response:

 double PI=3.14; 
Char ch [100].
Lf sprintf (ch, "%", PI);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related