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

La description

Il efface le contenu de la chaîne, qui devient une chaîne vide.

Déclaration

Voici la déclaration pour std :: string :: clear.

void clear();

C ++ 11

void clear() noexcept;

Paramètres

aucun

Valeur de retour

aucun

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

#include <iostream>
#include <string>

int main () {
   char c;
   std::string str;
   std::cout << "Please type some lines of text. Enter a start (*) to finish:\n";
   do {
      c = std::cin.get();
      str += c;
      if (c=='\n') {
         std::cout << str;
         str.clear();
      }
   } while (c!='*');
   return 0;
}

L'exemple de sortie devrait être comme ceci -

Please type some lines of text. Enter a start (*) to finish:
sairam.krishna *