Can you print out the value of a variable in a MFC MessageBox
Jul 13, 2011 at 6:13pm Jul 13, 2011 at 6:13pm UTC
Hey,
I am wondering if it is possible to display the value of a varible in a message box. I am using MFC C++ 6.0. I am displaying a messagebox by using AfxMessageBox("").
Thanks In Advance!!!
Jul 13, 2011 at 6:38pm Jul 13, 2011 at 6:38pm UTC
It is possible. You just have to convert your variable to a c-string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
//...
#include <sstream>
#include <string>
//...
int my_int = 5;
double my_double = 5.5;
std::string my_string = "lalala" ;
std::stringstream buffer;
buffer << "my int is: " << my_int << '\n' ;
buffer << "my double is: " << my_double << '\n' ;
buffer << "my string is: \"" << my_string << '\"' ;
AfxMessageBox(buffer.str().c_str());
//...
Topic archived. No new replies allowed.