C++ String Library - operator+=



Description

It extends the string by appending additional characters at the end of its current value.

Declaration

Following is the declaration for std::string::operator+=

string& operator+= (const string& str);

C++11

string& operator+= (const string& str);

Parameters

  • str − It is a string object.

  • c − It is a character object.

Return Value

It returns *this.

Exceptions

if an exception is thrown, there are no changes in the string.

Example

In below example for std::string::operator+=.

#include <iostream>
#include <string>

int main () {
   std::string name ("Sairamkrishna");
   std::string family ("Mammahe");
   name += " Prasad. ";
   name += family;
   name += '\n';

   std::cout << name;
   return 0;
}
Sairamkrishna Prasad. Mammahe
string.htm
Advertisements