Bibliothèque de chaînes C ++ - find_last_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_last_not_of.

size_t find_last_not_of (const string& str, size_t pos = npos) const;

C ++ 11

size_t find_last_not_of (const string& str, size_t pos = npos) const noexcept;

C ++ 14

size_t find_last_not_of (const string& str, size_t pos = npos) 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_last_not_of.

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

int main () {
   std::string str ("It erases trailing white-spaces   \n");
   std::string whitespaces (" \t\f\v\n\r");

   std::size_t found = str.find_last_not_of(whitespaces);
   if (found!=std::string::npos)
      str.erase(found+1);
   else
      str.clear();

   std::cout << '[' << str << "]\n";

   return 0;
}

L'exemple de sortie devrait être comme ceci -

[It erases trailing white-spaces]