Easy C++ MessageBox question.

Hi guys!

I know this is going to be one of those things where it turns out that it was something really small, simple and obvious but I am having trouble making a messagebox in C++ MFC application display a string.

Here is what I have:

string testVariable = " Testing.";

AfxMessageBox(_T("Test message." + testVariable));

I want the messagebox to display both the text and the variable but it only displays the text right now. I know that this is going to be a facepalm moment when I get the answer, oh well.

Thank you in advance.
Try adding them up into a string and passing the string in as the message.
_T is a macro for specifying the type of a string literal and you don't have a string literal here.

Since you're using a function that is TCHAR aware, use a string type that is as well.

Untested:
1
2
    CString testVariable(" Testing.");
    AfxMessageBox(_T("Test message.") + testVariable);


[Edit: Actually, you probably want to make sure the resulting CString object sticks around:
1
2
3
    CString testVAriable(" Testing.");
    CString message = _T("Test message.") + testVariable;
    AfxMessageBox(message);
]
Last edited on
THanks guys. After I made this post I actually solved my own issue but I will still give ya credit for being helpful and respoding. Cheers!
Topic archived. No new replies allowed.