Bibliothèque de chaînes C ++ - ajouter

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 :: append.

string& append (const string& str);

C ++ 11

string& append (const string& str);

C ++ 14

string& append (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.

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 :: append.

#include <iostream>
#include <string>

int main () {
   std::string str;
   std::string str2="Writing ";
   std::string str3="print 10 and then 5 more";

   str.append(str2);
   str.append(str3,6,3);
   str.append("dots are cool",5);
   str.append("here: ");
   str.append(10u,'.');
   str.append(str3.begin()+8,str3.end());
   str.append<int>(5,0x2E);
   std::cout << str << '\n';
   return 0;
}
Writing 10 dots here: .......... and then 5 more.....