What is `CString`?

CString is neither a C nor a C++ type. It appears to be a Microsoft invention that is essentially an alternative to std::string:

  • CString objects can grow as a result of concatenation operations.
  • CString objects follow “value semantics.” Think of a CString object as an actual string, not as a pointer to a string.
  • You can freely substitute CString objects for const char* and LPCTSTR function arguments.
  • A conversion operator gives direct access to the string’s characters as a read-only array of characters (a C-style string).

I recommend ignoring it, so that:

(a) people know what you are talking about;
(b) your code is portable;
(c) you are writing C++ that everybody can rationalise about according to the worldwide-accepted ISO C++ standard that many, many people spend many, many hours arguing about for this express purpose (y’know, as opposed to a few guys in a room in one company’s office).

It will only be available when you are programming with Microsoft Visual C++, which is substantially limiting.

Leave a Comment