Partager via


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
);

Parameters

  • 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.

Remarks

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.

Example

// 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   

Requirements

Header: cstringt.h

See Also

Reference

CStringT Class

Other Resources

CStringT Members