-
July 13th, 2011, 06:23 PM
#1
STL string VS ATL/MFC string
when do you choose to use STL string and when do you choose to use ATL or MFC string? What's the pro's and con's of STL and ATL/MFC String?
-
July 13th, 2011, 07:43 PM
#2
Re: STL string VS ATL/MFC string
There have been plenty of threads on this. Here is just one:
http://www.codeguru.com/forum/showthread.php?t=319932
Regards,
Paul McKenzie
-
July 13th, 2011, 08:11 PM
#3
Re: STL string VS ATL/MFC string
Originally Posted by Paul McKenzie
There have been plenty of threads on this. Here is just one:
[...]
Yes, and already post #3 from the thread you linked to (from 2004!) states:
Originally Posted by wien
And please do a search.. There have been oodles of threads about this in the past.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
July 13th, 2011, 09:47 PM
#4
Re: STL string VS ATL/MFC string
std::string is standard. Unless you have some particular reason to do otherwise, it's always better to stick with the standard library.
-
July 14th, 2011, 03:12 AM
#5
Re: STL string VS ATL/MFC string
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)
Victor Nijegorodov
-
July 14th, 2011, 06:07 AM
#6
Re: STL string VS ATL/MFC string
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.
...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.
Best regards,
Igor
-
July 14th, 2011, 07:03 AM
#7
Re: STL string VS ATL/MFC string
Originally Posted by Igor Vartanov
Unless project heavily depends on STL
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
-
July 14th, 2011, 01:03 PM
#8
Re: STL string VS ATL/MFC string
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.
Best regards,
Igor
-
July 14th, 2011, 01:22 PM
#9
Re: STL string VS ATL/MFC string
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.
For example, CString has GetBuffer.
Code:
CString sPath;
GetModuleFileName( NULL, sPath.GetBuffer( MAX_PATH ), MAX_PATH );
sPath.ReleaseBuffer( );
It also is ANSI/UNICODE aware so you don't need to spend time with conversions.
-
July 14th, 2011, 01:34 PM
#10
Re: STL string VS ATL/MFC string
Originally Posted by Igor Vartanov
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.
For example, CString has GetBuffer.
Code:
CString sPath;
GetModuleFileName( NULL, sPath.GetBuffer( MAX_PATH ), MAX_PATH );
sPath.ReleaseBuffer( );
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.
-
July 14th, 2011, 01:41 PM
#11
Re: STL string VS ATL/MFC string
Originally Posted by Lindley
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
Code:
#include <atlstr.h>
-
July 15th, 2011, 02:06 AM
#12
Re: STL string VS ATL/MFC string
Originally Posted by Lindley
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|