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

La description

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

Déclaration

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

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

C ++ 11

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

C ++ 14

size_t find_first_not_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

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

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

int main () {
   std::string str ("It looks for non-alphabetic characters...");

   std::size_t found = str.find_first_not_of("abcdefghijklmnopqrstuvwxyz ");

   if (found!=std::string::npos) {
      std::cout << "The first non-alphabetic character is " << str[found];
      std::cout << " at position " << found << '\n';
   }

   return 0;
}

L'exemple de sortie devrait être comme ceci -

The first non-alphabetic character is I at position 0