#include <string> size_type rfind( const string& str, size_type index ); size_type rfind( const char* str, size_type index ); size_type rfind( const char* str, size_type index, size_type num ); size_type rfind( char ch, size_type index );
The rfind() function either:
For example, in the following code, the first call to rfind() returns string::npos, because the target word is not within the first 8 characters of the string. However, the second call returns 9, because the target word is within 20 characters of the beginning of the string.
int loc; string s = "My cat's breath smells like cat food."; loc = s.rfind( "breath", 8 ); cout << "The word breath is at index " << loc << endl; loc = s.rfind( "breath", 20 ); cout << "The word breath is at index " << loc << endl;