Skip to main content
GameDev.net gamedev.net
🔒 Locked

CString

Started by mea36 Jan 22, 2007 at 3:44 PM 3 replies 1.1k views
Original Post
mea36
mea36
Hey, I am debugging someone else's code and I came across
typedef ATL::CStringT< TCHAR, StrTraitMFC_DLL< TCHAR > > CString;
I have no clue what it means. Can anyone help me? I am using Visual Studio 2005 and I think he was using Visual Studio 2003.
Emmanuel Deloget
Emmanuel Deloget
Quote:
Original post by mea36
Hey,
I am debugging someone else's code and I came across
typedef ATL::CStringT< TCHAR, StrTraitMFC_DLL< TCHAR > > CString;
I have no clue what it means. Can anyone help me? I am using Visual Studio 2005 and I think he was using Visual Studio 2003.


It means that the CString type (a string type from the MFC) is a typedef to a the template class ATL::CStringT which is defined with its parameter TCHAR (the chracter type; TCHAR resolves to "char" if UNICODE is mot defined, or wchar_t if UNICODE is defined) and StrTraitMFC_DLL (another template class that defines the char traits (ie. properties) of the type TCHAR.

In most case, this is not something you have to deal to.

Basically, the goal of this declaration is to create the type CString (CString is used quite extensively in the Microsoft Foundation Library).

Regards,
mea36
mea36
Thanks, that was helpful.

Quote:
Original post by Emmanuel Deloget
(CString is used quite extensively in the Microsoft Foundation Library).

If the code uses CString does that mean that the project isn't portable? What are the advantages of CString?
TheUnbeliever
TheUnbeliever
If you're using ATL (Active Template Library) and MFC (Microsoft Foundation Classes) your code isn't portable as-is (as they're both MS libraries) - but you're unlikely to care by that point.

I don't know the advantages of CString in the general case, but I'm guessing you *need* it to use one or both of the above.
[TheUnbeliever]
Emmanuel Deloget
Emmanuel Deloget
Quote:
Original post by TheUnbeliever
If you're using ATL (Active Template Library) and MFC (Microsoft Foundation Classes) your code isn't portable as-is (as they're both MS libraries) - but you're unlikely to care by that point.


Trueness inside. It is also possible that the person who wrote the code only used CString. If this is the case then you'd better replace it by std::string (note that CString provide a Format() method which is similar to sprintf(); std::string doesn't provide such method, although you can get a similar functionality by using std::stringstream (in )).

Quote:
Original post by TheUnbeliever
I don't know the advantages of CString in the general case, but I'm guessing you *need* it to use one or both of the above.


The only advantage I see is... well, I don't see any advantage... Even Format() is a Bad Thing (not type safe, not very secure and error prone; just as sprintf() in fact).

The only reason to use it is that it is tied to the MFC, meaning that if you use the MFC, it is going to be easier to use CString than std::string (but even this is debatable).

Regards,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.