CStringT::operator =

The CStringT assignment (=) operator reinitializes an existing CStringT object with new data.

CString& operator=(
   const VARIANT& var
);
CString& operator=(
   wchar_t ch
);
CString& operator=(
   char ch
);
CString& operator=(
   const unsigned char* pszSrc
);
CString& operator=(
   PCYSTR pszSrc
);
CString& operator=(
   PCXSTR pszSrc
);
template <bool bMFCDLL>
CString& operator=(
   const CSimpleStringT<BaseType, bMFCDLL>& strSrc
);
CString& operator=(
   const CStringT& strSrc
);

var

A variant-type object to be copied into this CStringT object.

ch

A single character.

strSrc

A null-terminated string to be copied into this CStringT object.

pszSrc

A CStringT to be copied into this CStringTobject.

If the destination string (that is, the left side) is already large enough to store the new data, no new memory allocation is performed. You should be aware that memory exceptions can occur whenever you use the assignment operator because new storage is often allocated to hold the resulting CStringT object.

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

CAtlString s1, s2;        // Empty CAtlString objects

s1 = _T("cat");            // s1 = "cat"
s2 = s1;                  // s1 and s2 each = "cat"
s1 = _T("the ") + s1;      // Or expressions
s1 = _T('x');              // Or just individual characters   

Header: cstringt.h

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft