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

La description

Il recherche dans la chaîne le dernier 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_last_of.

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

C ++ 11

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

C ++ 14

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

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_of.

#include <iostream>
#include <string>
#include <cstddef>
void SplitFilename (const std::string& str) {
   std::cout << "Splitting: " << str << '\n';
   std::size_t found = str.find_last_of("/\\");
   std::cout << " path: " << str.substr(0,found) << '\n';
   std::cout << " file: " << str.substr(found+1) << '\n';
}

int main () {
   std::string str1 ("/usr/bin/man");
   std::string str2 ("c:\\windows\\winhelp.exe");

   SplitFilename (str1);
   SplitFilename (str2);

   return 0;
}