Display an int variable in a MessageBox

c++, winapi

Solution

Why bother with C-style strings if you tagged C++?

Although Mark Ransom provided MFC solution (which is perfectly valid), here is a Standard C++ one:

int index1 = 1;
std::string test1 = std::to_string(index1);
MessageBoxA(NULL, test1.c_str(), "testx", MB_OK);

References:

- std::to_string();

- Arrays are evil

Use `boost::format` for more sophisticated formatting.

Problem

I am working on an old app written in Visual C++ 6.0. I am trying to display an `int` variable in a `MessageBox` for debugging reasons. Here is my code, I thought this would be a simple process, but I am just learning C++. The two lines that are commented I have tried as well with similar errors. Below is the error I am getting. ``` int index1 = 1; char test1 = index1; // char var1[] = index1; // char *varGo1 = index1; MessageBox(NULL, test1, "testx", MB_OK); ``` error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'char' to 'const char *'

Original source