Create a temporary buffer to store your string in and use sprintf
, change the formatting depending on your variable type. For your first example the following should work:
char buff[100];
string name = "stackoverflow";
sprintf_s(buff, "name is:%s", name.c_str());
cout << buff;
Then call message box with buff as the string argument
MessageBox(hWnd, buff, "Msg title", MB_OK | MB_ICONQUESTION);
for an int change to:
int d = 3;
sprintf_s(buff, "name is:%d",d);