basic_string::rend

逆順の文字列内の最後の要素の次の場所を指定する反復子を返します。

const_reverse_iterator rend( ) const;
reverse_iterator rend( );

戻り値

逆順の文字列内の最後の要素の次の場所を示す逆のランダム アクセス反復子。

解説

rend、反転した文字列と 終了 が文字列で使用するために使用されます。

rend の戻り値が const_reverse_iteratorに割り当てると、文字列オブジェクトは変更できません。 rend の戻り値が reverse_iteratorに割り当てると、文字列オブジェクトは変更できます。

反転反復子を文字列の末尾に到達したかどうかをテストするためにrend を使用できます。

rend によって返された値は逆参照しないでください。

使用例

// basic_string_rend.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( )
{
   using namespace std;
   string str1 ("Able was I ere I saw Elba"), str2;
   basic_string <char>::reverse_iterator str_rIter, str1_rIter, str2_rIter;
   basic_string <char>::const_reverse_iterator str1_rcIter;

   str1_rIter = str1.rend ( );
   str1_rIter--;
   cout << "The last character-letter of the reversed string str1 is: "
        << *str1_rIter << endl;
   cout << "The full reversed string str1 is:\n ";
   for ( str_rIter = str1.rbegin( ); str_rIter != str1.rend( ); str_rIter++ )
      cout << *str_rIter;
   cout << endl;

   // The dereferenced iterator can be used to modify a character
    *str1_rIter = 'o';
   cout << "The last character-letter of the modified str1 is now: "
        << *str1_rIter << endl;
   cout << "The full modified reversed string str1 is now:\n ";
   for ( str_rIter = str1.rbegin( ); str_rIter != str1.rend( ); str_rIter++ )
      cout << *str_rIter;
   cout << endl;

   // The following line would be an error because iterator is const
   // *str1_rcIter = 'T';

   // For an empty string, end is equivalent to begin
   if ( str2.rbegin( ) == str2.rend ( ) )
      cout << "The string str2 is empty." << endl;
   else
      cout << "The stringstr2  is not empty." << endl;
}
  

必要条件

ヘッダー: の <文字列>

名前空間: std

参照

関連項目

basic_string クラス