CString error
-
Hi all, I've recently gotten VC++ 2005 and am having problems with the CString class. Here three examples and the errors I'm getting: 1. AfxMessageBox("some text"); //none of the 2 overloads could convert all the argument types 2. void MyFunction(int i, CString str); ... MyFunction(1, "some text"); //cannot convert parameter 2 from 'const char [4]' to 'CString' but CString str; str = "some text"; MyFunction(1, str); //works fine 3. Also, the declaration CString str = "some text"; does not work. The error message is: error C2440: 'initializing' : cannot convert from 'const char [26]' to 'ATL::CStringT' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] 1> Constructor for class 'ATL::CStringT' is declared 'explicit' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] Anyone can tell me if there was a change to the CString class? Thx, Ralf. ralf.riedel@usm.edu
-
Hi all, I've recently gotten VC++ 2005 and am having problems with the CString class. Here three examples and the errors I'm getting: 1. AfxMessageBox("some text"); //none of the 2 overloads could convert all the argument types 2. void MyFunction(int i, CString str); ... MyFunction(1, "some text"); //cannot convert parameter 2 from 'const char [4]' to 'CString' but CString str; str = "some text"; MyFunction(1, str); //works fine 3. Also, the declaration CString str = "some text"; does not work. The error message is: error C2440: 'initializing' : cannot convert from 'const char [26]' to 'ATL::CStringT' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] 1> Constructor for class 'ATL::CStringT' is declared 'explicit' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] Anyone can tell me if there was a change to the CString class? Thx, Ralf. ralf.riedel@usm.edu
-
IIRC, VS2005 uses Unicode for new projects for default, so try:
AfxMessageBox(L"Some text");
Basically, insert L before your strings (to indicate it is a Unicode string), or change your default project settings to MBCS.
I would use the
_T
macro from<tchar.h>
. i.e.AfxMessageBox(_T("Some text"));
This way you can build ANSI or UNICODE builds without altering the code. Steve
-
I would use the
_T
macro from<tchar.h>
. i.e.AfxMessageBox(_T("Some text"));
This way you can build ANSI or UNICODE builds without altering the code. Steve
-
Indeed, but, personally, I only ever build for Unicode - using the UnicoWS library for (dwindling) Win9x support. :)
Thanks for the replies. Got the code up and running. ralf.riedel@usm.edu