This documentation is archived and is not being maintained.

CString Semantics 

Even though CString objects are dynamic objects that can grow, they act like built-in primitive types and simple classes. Each CString object represents a unique value. CString objects should be thought of as the actual strings rather than as pointers to strings.

You can assign one CString object to another. However, when you modify one of the two CString objects, the other CString object is not modified, as shown by the following example:

CString s1, s2;
s1 = s2 = "hi there";

if( s1 == s2 )            // TRUE - they are equal

s1.MakeUpper();        // Does not modify s2
if( s2[0] == 'h' )        // TRUE - s2 is still "hi there"

Note in the example that the two CString objects are considered "equal" because they represent the same character string. The CString class overloads the equality operator (==) to compare two CString objects based on their value (contents) rather than their identity (address).

See Also

Other Resources

Strings (ATL/MFC)