These are the type of random errors you sometimes experience pre-service packs...
I hope your experience with VS2010 gets better, I've seen a lot of improvements from the usability stand point and the better standard C++ compliance is certainly a great step forward for MS. Good luck!
I guess your project setting in UNICODE. If so, CString will be using wide char (wchar_t) to manipulate strings. The problem is, you are treating them as multibyte characters (char). I suggest you to use TCHAR type instead of hard coding char & wchar_t, as it can be used well in both unicode and multibyte configurations.
what about setting the project as character set : Not set,
in this case, as your suggestion, do I need to replaced all char to TCHAR in the whole project. Thats a lot . . I was trying to avoid much touch in the project implementation
How about having my own class CMyString : public ATL::CString, can i do something in this way to avoid less touch to the project code ? Please note that the current project uses char not wchar_t. Project setting could be change according to our convenience
1. If character set is 'Not Set', i think char will work.
2. CMyString can be alright. Write it to take char only, and internally convert them to wchar_t if the Character Set is 'Unicode' (using APIs like MultiByteToWideChar) and let the CString base class to do the string operations. This will help you to retain all the char types in existing code, provided you are replacing all usage of CString with CMyString. And the implied issue is that you won't be able to manipulate non-english characters with CMyString.
I followed the same way as you suggested. But found a very interesting problem. Following is the explanation:
I should be able to use + operator like below..
strTemp = "aa" + strTemp;
And for this I need to overload the +operator.(Reason:: I get a error which says::
error C2678: binary '+' : no operator found which takes a left-hand operand of type 'const wchar_t '
I am not able to find a appropriate way to call the operator+ of the base class, or any other way to solve the same. [ All I need is, inside operator+ overloading , to convert the char to wchar and then pass it to the base class]
I don't understand why you do not use the CStringT[^] class, which already includes the code for overloading the + operator. What extra functionality does your derived class offer that CStringT does not already include?
I think you need to bite the bullet and convert all your char variables and constants to TCHAR. If you do not, you will continue to have problems like this. If it were easy to solve the multi-byte to Unicode to multi-byte character conversion issues that solution would be part of the CString class.
The changes you need to make are mechanical. You need to put _T() around all your string and character literals. You need to change all your char variables to TCHAR.
I don't know how big your project is, or if you have access to all the source. I suspect you have spent more time trying to avoid the issue than a proper fix would require.
You cannot use casting to convert from a large element type to a smaller one without potential loss of data, you must use some form of conversion. If you stick with the default CString[^] class it will handle either char or wchar_t depending on your project settings. If your project needs to use both Unicode and MBCS then you need to provide conversion functions at the appropriate parts of your application. If it will only ever use one or the other but you need to provide a version that will handle each type then use TCHAR as the type for all your character variables and _T("constant string") macros for all constants. That way you can simply rebuild your project to handle the appropriate encoding.
I need to avoid MFC from my existing project, and convert to ATL. I am using STL for the most of the conversion (defining my own class for MFC type)
CString has been use extensively in the project. So I guess its better to implement my own CString class. So that I dont need to touch all the implementation.
I found out that ATL also has CString
typedef CAtlString CString;
So, if project setting avoids MFC, then CString will be refererd from this ATL CString class. But the problem is I need to touch and convert many code like
"xx" to L"xx"char to wchar_t
Can I have a efficient way, in order to avoid touching much implementation, and character code supportness.
Shall I override this ATL CString class? or better right my own?
considering about the supporting of character type (Unicode/others), could you Please suggest me, or advice me.
The reason you're having those issues is that your original project probably had a setting of "Use Multi-Byte" characters or "ASCII" or something similar and now you seem to be attempting to use unicode. If you change you new project settings to use multi-byte characters or ASCII you won't have that problem but if you must use unicode, then you'll have to face the issue regardless. There may be some macros out there to help you out though, try searching google for them. Macros can be error prone however, so if its your intention to continue with unicode then you'll have to address the character and string definitions.
Could anyone please tell me, is there any way to separate the definition of the methods of a template class ,from header file to .cpp file.
I know the way, wherein, we define all the methods in a file( with extension other then .cpp), and include the file at the end of the header file of the template class.
But this method looks no good, is there any clean and usual way just like other class.
The reason for placing definitions in a header file is so that they can be included in many implementation (.cpp) files. If your definitions are only used within one implementation file then you can put them at the top of that file.
Or did I misunderstand your question?
The best things in life are not things.
Last Visit: 31-Dec-99 18:00 Last Update: 22-Sep-23 3:08