Condividi tramite


basic_string::rbegin

Restituisce un iteratore al primo elemento in una stringa invertita.

const_reverse_iterator rbegin( ) const;
reverse_iterator rbegin( );

Valore restituito

Restituisce un iteratore di accesso casuale al primo elemento di una stringa invertita, il routing che sarebbe l'ultimo elemento della stringa unreversed corrispondente.

Note

rbegin viene utilizzato con una stringa invertita come inizio viene utilizzato con una stringa.

Se il valore restituito di rbegin viene assegnato a const_reverse_iterator, l'oggetto string non può essere modificato. Se il valore restituito di rbegin viene assegnato a reverse_iterator, l'oggetto string può essere modificato.

rbegin può essere utilizzato per inizializzare un'iterazione tramite una stringa indietro.

Esempio

// 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;
}
  

Requisiti

Intestazione: <string>

Spazio dei nomi: std

Vedere anche

Riferimenti

Classe basic_string