共用方式為


basic_string::rend

傳回處理成功最後一個項目的位置會以反轉的字串的Iterator。

const_reverse_iterator rend( ) const;
reverse_iterator rend( );

傳回值

解決成功最後一個項目的位置會以反轉的字串的反向隨機存取Iterator。

備註

無效 結束 搭配字串,rend 搭配反向的字串。

如果 rend 的傳回值指派給 const_reverse_iterator,無法修改字串物件。 如果 rend 的傳回值指派給 reverse_iterator,可以修改字串物件。

rend 用來測試反向Iterator是否已到達字串的結尾。

不應該取值 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;
}
  

需求

標題: <string>

命名空間: std

請參閱

參考

basic_string Class