Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32 C++ -- How to pass int or float value to messagebox

968 views
Skip to first unread message

Eurosport1

unread,
Nov 20, 2000, 3:00:00 AM11/20/00
to
How can I pass a int or float value to a MessageBox... I can't remember a way of
doing... I was told along time ago to use something like ostringstream but I
can't figure it out... Any input would be great... I am trying to do some on
screen debugging.


eurosport

Katy Mulvey [MVP]

unread,
Nov 20, 2000, 3:00:00 AM11/20/00
to
In <090d01c05364$90efe610$4c862ecf@cpmsftngxa09>, Eurosport1

You need to somehow format the numeric value into a string. One
method would be to create an ostringstream, and just stream
the number in, and extract the formatted character string to
show in the MessageBox. If you've tried this and failed,
it might be useful to post your attempt and say how it's
gone wrong.

If you're using MFC, the simplest way is probably to use
CString::Format.

If you're more comfortable with the C libraries, create
a buffer and use sprintf to fill the buffer appropriately.

Depending on what you're debugging, you might also consider
using OutputDebugString instead of MessageBox, since a
message box will change the messages sent to your window.
Strings printed with OutputDebugString will be displayed
by the debugger if you're running your program from the
debugger, or you can use a third party program like
DebugView (available on www.sysinternals.com) to see
those messages. This is often more convinient, since you
can save the debug messages to a file.

--
- Katy

Katy Mulvey HOME: http://mulvey.dyndns.com/~katy
Please post replies to VC++ FAQ: http://www.mvps.org/vcfaq
the newsgroup, thanks! MVP/VC++: http://support.microsoft.com/support/mvp

Morgan Vermef

unread,
Nov 20, 2000, 3:00:00 AM11/20/00
to
Katy,

Thanx for the information but I guess for some reason I don't completely
know the proper way to format the values into string values using
ostringstream...

--

Morgan Vermef
--
mve...@yahoo.com
--
MS Allegiance Chancellor Team
ZONEIDs: Aviator1/Eurosprt1
--
ICQ# 5827864


"Katy Mulvey [MVP]" <k...@mvps.org> wrote in message
news:slrn91jp41....@teleman.aa2ys.ampr.org...

s.t. greives

unread,
Nov 21, 2000, 3:00:00 AM11/21/00
to
Eurosport1 wrote:
>
> How can I pass a int or float value to a MessageBox...
You gotta be more specific as it's not clear what you mean. Would the following solve your
problem:

char sBuffer[100];
sprintf(sBuffer,"my float = %f", floatVar );
MessageBox(NULL,sBuffer,"See Ma? No hands", MB_OK);

? If not, please elaborate.

I can't remember a way of
> doing... I was told along time ago to use something like ostringstream but I
> can't figure it out... Any input would be great... I am trying to do some on
> screen debugging.
>

> eurosport

Morgan Vermef

unread,
Nov 21, 2000, 3:00:00 AM11/21/00
to
that works thanx... works really well as a matter of fact

--

Morgan Vermef
--
mve...@yahoo.com
--
MS Allegiance Chancellor Team
ZONEIDs: Aviator1/Eurosprt1
--
ICQ# 5827864


"s.t. greives" <simpleto...@nosedive.worldnet.att.net> wrote in
message news:3A1A5ADE...@nosedive.worldnet.att.net...

Craig Powers

unread,
Nov 22, 2000, 3:00:00 AM11/22/00
to
Morgan Vermef wrote:
>
> Thanx for the information but I guess for some reason I don't completely
> know the proper way to format the values into string values using
> ostringstream...

// ...

#include <sstream>
#include <string>

//...

std::ostringstream myOSS;

// Assume that "value" is coming from somewhere in the //... above
myOSS << "The value is: " << value;

MessageBox(NULL, myOSS.str().c_str(), "Title", MB_OK);

//...


Pretty much, the same way you format values into any sort of C++
stream. If you need to control the format of the value, you
should also look at the I/O manipulators. I think you'd need
to #include <iomanip> to use them.

Mike Thomson

unread,
Dec 13, 2022, 2:43:49 PM12/13/22
to
Thanks to Craig Powers
it worked well..
0 new messages