public member function
<string>
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
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// 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:
Basic template member declaration
( basic_string<charT,traits,Allocator> )
1 2
|
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)