cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Strings library : string : string::rend
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::rend public member function
      reverse_iterator rend();
const_reverse_iterator rend() const;

Return reverse iterator to reverse end

Returns a reverse iterator referring to the element right before the first character in the string, which is considered the reverse end.

rend refers to the character right before the one that would be referred to by member begin.

Parameters

none

Return Value

A reverse iterator to the reverse end of the string (i.e., the element right before its first 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 rend();
const_reverse_iterator rend() const;

See also

string::rbegin Return reverse iterator to reverse beginning (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