operator+ (<string>)

Concatenates two string objects.

template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator> operator+(
      const basic_string<CharType, Traits, Allocator>& _Left,
      const basic_string<CharType, Traits, Allocator>& _Right
   );
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator> operator+(
      const basic_string<CharType, Traits, Allocator>& _Left,
      const CharType* _Right
   );
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator> operator+(
      const basic_string<CharType, Traits, Allocator>& _Left,
      const CharType _Right
   );
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator> operator+(
      const CharType* _Left,
      const basic_string<CharType, Traits, Allocator>& _Right
   );
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator> operator+(
      const CharType _Left,
      const basic_string<CharType, Traits, Allocator>& _Right
   );
template<class CharType, class Traits, class Allocator>
    basic_string<CharType, Traits, Allocator>&& operator+(
        const basic_string<CharType, Traits, Allocator>& _Left,
        const basic_string<CharType, Traits, Allocator>&& _Right
);
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator>&& operator+(
      const basic_string<CharType, Traits, Allocator>&& _Left,
      const basic_string<CharType, Traits, Allocator>& _Right
);
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator>&& operator+(
      const basic_string<CharType, Traits, Allocator>&& _Left,
      const basic_string<CharType, Traits, Allocator>&& _Right
);
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator>&& operator+(
      const basic_string<CharType, Traits, Allocator>&& _Left,
      const CharType *_Right
);
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator>&& operator+(
      const basic_string<CharType, Traits, Allocator>&& _Left,
      CharType _Right
);
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator>&& operator+(
      const CharType *_Left,
      const basic_string<CharType, Traits, Allocator>&& _Right
);
template<class CharType, class Traits, class Allocator>
   basic_string<CharType, Traits, Allocator>&& operator+(
      CharType _Left,
      const basic_string<CharType, Traits, Allocator>&& _Right
);

Parameters

  • _Left
    A C-style string or an object of type basic_string to be concatenated.

  • _Right
    A C-style string or an object of type basic_string to be concatenated.

Return Value

The string that is the concatenation of the input strings.

Remarks

The functions each overload operator+ to concatenate two objects of template class basic_string Class. All effectively return basic_string<CharType, Traits, Allocator>(_Left).append(_Right).

Example

// string_op_con.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;
   // Declaring an object of type basic_string<char>
   string s1 ( "anti" );
   string s2 ( "gravity" );
   cout << "The basic_string s1 = " << s1 << "." << endl;
   cout << "The basic_string s2 = " << s2 << "." << endl;

   // Declaring a C-style string
   char *s3 = "heroine";
   cout << "The C-style string s3 = " << s3 << "." << endl;

   // Declaring a character constant
   char c1 = '!';
   cout << "The character constant c1 = " << c1 << "." << endl;

   // First member function: concatenates an  object
   // of type basic_string with an object of type basic_string
   string s12 = s1 + s2;
   cout << "The string concatenating s1 & s2 is: " << s12 << endl;

   // Second & fourth member functions: concatenate an object
   // of type basic_string with an object of C-syle string type
   string s1s3 = s1 + s3;
   cout << "The string concatenating s1 & s3 is: " << s1s3 << endl;

   // Third & fifth member functions: concatenate an object
   // of type basic_string with a character constant
   string s1s3c1 = s1s3 + c1;
   cout << "The string concatenating s1 & s3 is: " << s1s3c1 << endl;
}
The basic_string s1 = anti.
The basic_string s2 = gravity.
The C-style string s3 = heroine.
The character constant c1 = !.
The string concatenating s1 & s2 is: antigravity
The string concatenating s1 & s3 is: antiheroine
The string concatenating s1 & s3 is: antiheroine!

Requirements

Header: <string>

Namespace: std

See Also

Reference

basic_string Class

<string>

string::operator+