string rend() in C++

rend(): This function returns a read/write reverse iterator that points to one before 

the first character in the given string. 

Note: Iteration is done in reverse element order.

This function is available in the below file.

File: basic_string.h

Parameters: No parameters are required for this function

Syntax:

string:: reverse_iterator it = str.rend()

For Example:

str = "abc"

str.rend() => It points to one before the first character of the string.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str = "abc";

    string ::reverse_iterator it = str.rend();

    cout << *(it - 1<< "\n";

    return 0;
}


No comments:

Post a Comment