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

La description

Il recherche dans la chaîne la dernière occurrence de la séquence spécifiée par ses arguments.

Déclaration

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

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

C ++ 11

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

C ++ 14

size_t rfind (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 :: rfind.

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

int main () {
   std::string str ("sairamkrishna mammahe is a one of the tech person in tutorialspoint.com");
   std::string key ("mammahe");

   std::size_t found = str.rfind(key);
   if (found!=std::string::npos)
      str.replace (found,key.length(),"tech");

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

   return 0;
}

L'exemple de sortie devrait être comme ceci -

sairamkrishna tech is a one of the tech person in tutorialspoint.com