Translations of this page?:

rfind

Syntax:

    #include <string>
    size_type rfind( const string& str, size_type index = npos ) const;
    size_type rfind( const charT* str, size_type index = npos ) const;
    size_type rfind( const charT* str, size_type index, size_type num ) const;
    size_type rfind( charT ch, size_type index = npos ) const;

rfind()関数は、検索文字列を”index”から逆順に文字列を検索し、最後に見つかった位置を返します。

  • もし文字列が見つからないと、string::not_foundを返します。
  • 検索位置は、文字列の最初から0から数えます。
  • 逆順に検索を開始し、最後に現れる位置を返します。

次のサンプルコードでは最初にrfind()が呼ばれたときには、ターゲットとなる単語が9文字目にあるためにstring::nposが返されます。 しかし、文字列の20番目までには含まれるため、二回目に呼ばれたときには9が返ります。

     string::size_type 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;

Related Topics: find, find_first_not_of, find_first_of, find_last_not_of, find_last_of

 
• • • SitemapRecent changesRSScc