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

La description

Il recherche dans la chaîne le premier caractère qui correspond à l'un des caractères spécifiés dans ses arguments.

Déclaration

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

size_t find_first_of (const string& str, size_t pos = 0) const;

C ++ 11

size_t find_first_of (const string& str, size_t pos = 0) const noexcept;

C ++ 14

size_t find_first_of (const string& str, size_t pos = 0) const noexcept;

Paramètres

  • str - C'est un objet string.

  • len - Il est utilisé pour copier les caractères.

  • pos - Position du premier caractère à copier.

Valeur de retour

aucun

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

#include <iostream>
#include <string>
#include <cstddef>

int main () {
   std::string str ("It replaces the vowels in this sentence by asterisks.");
   std::size_t found = str.find_first_of("aeiou");
   while (found!=std::string::npos) {
      str[found]='*';
      found=str.find_first_of("aeiou",found+1);
   }

   std::cout << str << '\n';

   return 0;
}

L'exemple de sortie devrait être comme ceci -

It r*pl*c*s th* v*w*ls *n th*s s*nt*nc* by *st*r*sks.