Bibliothèque de chaînes C ++ - opérateur + =

La description

Il étend la chaîne en ajoutant des caractères supplémentaires à la fin de sa valeur actuelle.

Déclaration

Voici la déclaration pour std :: string :: operator + =

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

C ++ 11

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

Paramètres

  • str - C'est un objet string.

  • c - C'est un objet de caractère.

Valeur de retour

Il renvoie * this.

Des exceptions

si une exception est levée, il n'y a aucun changement dans la chaîne.

Exemple

Dans l'exemple ci-dessous pour 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