Adding two CString variables

Hi,
       I would like to know how to add two CString variables together so that it can be displayed in a MessageBox.  I'm using VS2005, MFC/C++

Example
CString directory = "C:\\Test\\";
CString filename = "Junk.txt";
CString directory_filename = directory + filename;  ??

MessageBox("File Saved to -->" + directory_filename); ??

Thanks,
arunykandAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
You are compiling as UNICODE and want to use 'CWnd::MessageBox()'? Then try
CString directory = _T("C:\\Test\\");
CString filename = _T("Junk.txt");
CString directory_filename = directory + filename; 
CString text = _T("File Saved to --> ");
CString output = text + directory_filename;

MessageBox((LPCTSTR)output,_T("Information"),MB_OK);

// alternatively:
::MessageBox(NULL,(LPCTSTR)output,_T("Information"),MB_OK);

Open in new window

0
 
jkrCommented:
Basically you got it, yet adding another step might help:
CString directory = "C:\\Test\\";
CString filename = "Junk.txt";
CString directory_filename = directory + filename; 
CString text = "File Saved to --> ";
CString output = text + directory_filename;

MessageBox(NULL,(LPCTSTR)output,"Information",MB_OK);

Open in new window

0
 
arunykandAuthor Commented:
JKR....
    I tried your suggestion, I got the following errors:

Error	15	error C2440: 'initializing' : cannot convert from 'const char [9]' to 'ATL::CStringT<BaseType,StringTraits>'	c:\projects\test.cpp	509


Error	18	error C2660: 'CWnd::MessageBoxW' : function does not take 4 arguments	c:\projects\test.cpp	515

Open in new window

0
 
arunykandAuthor Commented:
Thanks JKR!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.