It always depends...
If working with MFC application then IMHO using CString is better (more easy and convenient for MFC classes and Windows API as well)
Very true. Even with plain Win API I prefer to deal with ATL::CString. Unless project heavily depends on STL, or there is a direct requirement on the project to use std:string strings.
std::string is standard.
...which really matters for contemporary cross-platform projects. In its turn, CString strings had been considered "standard-like" in Windows world long before STL became a standard.
Last edited by Igor Vartanov; July 14th, 2011 at 06:09 AM.
Not sure how you qualify heavily, but the last project I worked on that did not use STL in pretty much every compilation unit, was when I was learning C++ and nobody had bothered to teach me about STL yet.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
the last project I worked on that did not use STL in pretty much every compilation unit, was when I was learning C++
Well then you gonna be surprised about how other teams are still able to ignore STL stuff and rely on their own/third party experience/libraries. Because of lots of reasons I really respect. (You know, the word 'standard' never made me thrill )
Last edited by Igor Vartanov; July 14th, 2011 at 01:05 PM.
For one thing, if you aren't stuck on using VC6, ATL::CString and MFC::CString are one and the same.
If you are coding in Windows and aren't concerned about cross platform compatibility, use CString. Why? because it has additional methods and constructors that are useful on Windows.
Well then you gonna be surprised about how other teams are still able to ignore STL stuff and rely on their own/third party experience/libraries. Because of lots of reasons I really respect. (You know, the word 'standard' never made me thrill )
If they have a really good toolset which is well-known by the team, then that's cool. Everyone develops their own toolset as they go if they're smart.
I unfortunately have met too many "programmers" who flinch at the first sign of a functor, though, and that's just not helpful.
Originally Posted by Arjay
If you are coding in Windows and aren't concerned about cross platform compatibility, use CString. Why? because it has additional methods and constructors that are useful on Windows.
It also is ANSI/UNICODE aware so you don't need to spend time with conversions.
Personally I find UTF-8 a lot more intuitive to deal with than UTF-16, and std::string is good enough for that. The stuff with GetBuffer can of course be done with std::vector<char>, although I'll grant it would be nice if it were available in the std::string class.
Personally I find UTF-8 a lot more intuitive to deal with than UTF-16, and std::string is good enough for that. The stuff with GetBuffer can of course be done with std::vector<char>, although I'll grant it would be nice if it were available in the std::string class.
The nice thing about CString is that it automatically handles ANSI and UNICODE when calling Windows api's, whereas std::string doesn't work so well when building in unicode. There are other methods that are helpful too like the BSTR methods when working with COM.
Many folks mistakenly tie CString to MFC and think they need to include MFC dlls.
This hasn't been the case in quite a while. All that is needed now is
The stuff with GetBuffer can of course be done with std::vector<char>, although I'll grant it would be nice if it were available in the std::string class.
note that with the new standard std::string stores chars contiguously, so this issue has been at least mitigated now.
Bookmarks