cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Strings library : string : rbegin
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Strings library
char_traits
classes:
· string
global functions:
· getline
· operator+
· operator<<
· operator>>
· comparison operators
· swap
string
string::string
member constants:
· string::npos
member functions:
· string::append
· string::assign
· string::at
· string::begin
· string::capacity
· string::clear
· string::compare
· string::copy
· string::c_str
· string::data
· string::empty
· string::end
· string::erase
· string::find
· string::find_first_not_of
· string::find_first_of
· string::find_last_not_of
· string::find_last_of
· string::get_allocator
· string::insert
· string::length
· string::max_size
· string::operator+=
· string::operator=
· string::operator[]
· string::push_back
· string::rbegin
· string::rend
· string::replace
· string::reserve
· string::resize
· string::rfind
· string::size
· string::substr
· string::swap

-

string::rbegin public member function
      reverse_iterator rbegin();
const_reverse_iterator rbegin() const;

Return reverse iterator to reverse beginning

Returns a reverse iterator referring to the last character in the string, which is considered the reverse beginning.

rbegin refers to the character right before the one that would be referred to by member end.

Parameters

none

Return Value

A reverse iterator to the reverse beginning of the string (i.e., the last character).

The type of this iterator is either string::reverse_iterator member type or string::const_reverse_iterator member type, which are compiler specific iterator types suitable to perform a reverse iteration through the elements of a string object.

Example

// string::rbegin and string::rend
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string str ("now step live...");
  string::reverse_iterator rit;
  for ( rit=str.rbegin() ; rit < str.rend(); rit++ )
    cout << *rit;
  return 0;
}

This code prints out the reversed content of a string character by character using a reverse iterator that iterates between rbegin and rend. Notice how even though the reverse iterator is increased, the iteration goes backwards through the string (this is a feature of reverse iterators).
The actual output is:

...evil pets won

Basic template member declaration

( basic_string<charT,traits,Allocator> )
      reverse_iterator rbegin();
const_reverse_iterator rbegin() const;

See also

string::rend Return reverse iterator to reverse end (public member function)
string::begin Return iterator to beginning (public member function)
string::end Return iterator to end (public member function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us