Question

I've only learned a little bit of ATL in the last couple of days (after realizing how much pain pure Win32 is) and also learned about WTL and MFC, and from what I see, there are quite a few different string classes available for me.

I used to do something like this:

#include <tchar.h>
#include <string>
namespace std { typedef basic_string<TCHAR> _tstring; }

and then use _tstring everywhere in my code. After learning some ATL, I learned that there's a CString class in atltmp.h. Apparently, there's another CString class in WTL, and yet another CString class in MFC.

I have no idea whether I will stick with ATL or whether I'll switch to WTL, MFC, or something else. But right now, I'm in the process of converting my Win32 code to ATL, and I'm not sure what to change and what to keep.

Should I make my strings use CString instead of _tstring? Is there any benefit in doing so, considering both executable size (excluding shared libraries) and portability/compatibility?

Was it helpful?

Solution 2

Something that I just read is that CString does not support null characters.

I guess I'll keep with STL, then.

OTHER TIPS

My preference would be to stick with CString for ATL / MFC / WTL. It's not like you have much of an option for portability if you're using those frameworks anyway; and you know what they say: When in Rome ...

Also, CString does have a few niceties about it

  • You can load resource strings from executables using CString::LoadString
  • Get direct access to the internal string buffer using CString::GetBuffer/ReleaseBuffer
  • Silently convert between CStringA & CStringW
  • Perform printf-like formatting using CString::Format
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top