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

La description

Il attribue une nouvelle valeur à la chaîne, remplaçant son contenu actuel.

Déclaration

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

tring& operator= (const string& str);

Paramètres

  • str - C'est un autre objet string.

  • s - Pointeur vers un tableau de caractères.

  • c - Caractère pour remplir la chaîne.

  • il - C'est un objet initializer_list.

Valeur de retour

Il renvoie * this.

Exceptions

Ne jetez jamais d'exceptions.

Exemple

Dans l'exemple ci-dessous pour std :: string :: operator =.

#include <string>

int main () {
   std::string str1, str2, str3;
   str1 = "Test string: ";
   str2 = 'abc';
   str3 = str1 + str2;

   std::cout << str3  << '\n';
   return 0;
}

L'exemple de sortie devrait être comme ceci -

Test string: c