basic_string::rbegin

返回反向字符串首个元素的迭代器。

const_reverse_iterator rbegin( ) const;
reverse_iterator rbegin( );

返回值

返回一个随机访问迭代器处于已撤消的字符串中的第一个元素,该解决什么是相应的 unreversed 字符串的最后一个元素。

备注

正值 开始 用于字符串,rbegin 使用的反转字符串。

如果返回值 rbeginconst_reverse_iterator,不能修改字符串对象。 如果返回值 rbegin 赋给 reverse_iterator,可修改字符串对象。

rbegin 可用来在字符串初始化向后迭代。

示例

// basic_string_rbegin.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.rbegin ( );
   // str1_rIter--;
   cout << "The first 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 = 'A';
   cout << "The first 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 = 'A';

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

要求

标头:< 字符串>

命名空间: std

请参见

参考

basic_string 类