The string::crend()
function returns the iterator that points to the first character in the string. It is used to traverse the string in reverse order.
Figure 1 shows the visual representation of the crend()
function.
This function requires a header file:
#include <string>
string.crend()
crend()
returns the iterator pointing to the first character in the string.
The example below shows how we can use crend()
to iterate the string in reverse order.
#include <iostream>using namespace std;//Header File#include <string>int main(){//string declaredstring STR="EDPRESSO";cout<<"The reverse order of string "<<STR<<": ";//iterator is being checked against crend() (first character) inorder to iterate the string in reversefor (auto iterator=STR.crbegin(); iterator !=STR.crend(); iterator++ )cout<<*iterator;}