This documentation is archived and is not being maintained.

CStringT::operator + 

Concatenates two strings or a character and a string.


friend CStringT operator+(
   const CStringT& str1,
   const CStringT& str2
);
friend CStringT operator+(
   const CStringT& str1,
   PCXSTR psz2
);
friend CStringT operator+(
   PCXSTR psz1
   const CStringT& str2,
);
friend CStringT operator+(
   char ch1
   const CStringT& str2,
);
friend CStringT operator+(
   const CStringT& str1,
   char ch2
);
friend CStringT operator+(
   const CStringT& str1,
   wchar_t ch2
);
friend CStringT operator+(
   wchar_t ch1
   const CStringT& str2,
);

Parameters

ch1

An ANSI or Unicode character to concatenate with a string.

ch2

An ANSI or Unicode character to concatenate with a string.

str1

A CStringT to concatenate with a string or character.

str2

A CStringT to concatenate with a string or character.

psz1

A pointer to a null-terminated string to concatenate with a string or character.

psz2

A pointer to a string to concatenate with a string or character.

There are seven overload forms of the CStringT::operator+ function. The first version concatenates two existing CStringT objects. The next two concatenate a CStringT object and a null-terminated string. The next two concatenate a CStringT object and an ANSI character. The last two concatenate a CStringT object and a Unicode character.

//typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString;
CAtlString s1("dog "), s2(" awake"), s3;  // Empty CAtlString objects

s1= "The " + s1;
s3= s1 + 'i';
s3= s3 + 's';
s3= s3 + s2;
_ASSERT(s3 == "The dog is awake");
Show: