CString::operator =

This assignment (=) operator reinitializes an existing CString object with new data. If the destination string — that is, the left side — is already large enough to store the new data, no new memory allocation is performed. Be aware that memory exceptions may occur whenever you use the assignment operator because new storage is often allocated to hold the resulting CString object.

const CString& operator =(
const CString& stringSrc );

const CString& operator =(
TCHAR ch );

const CString& operator =(
char ch );

const CString& operator = (
LPCWSTR lpsz );

const CString& operator =(
LPCSTR lpsz );

const CString& operator =(
const unsigned char* psz ); 
Parameters
  • stringSRC,
    Specifies CString objects to concatenate.
  • ch
    Specifies a character to concatenate to a string or to concatenate a string to.
  • lpsz
    Specifies a pointer to a null-terminated character string.
  • psz
    Specifies a null-terminated string to be copied into this CString object.

Example

The following example demonstrates the use of CString::operator =.

// example for CString::operator =
CString s1, s2;        // Empty CString objects

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

Requirements

  Windows CE versions: 1.0 and later
  Header file: Declared in Afx.h
  Platform: H/PC Pro, Palm-size PC, Pocket PC

See Also

CString::CString