string crend() in C++

crend(): It returns a read-only (constant) reverse iterator that points to one 

before the first character in the string. 

Note: Iteration is done in reverse element order.

Parameter: No parameters are required for this function.

Syntax:

string ::const_reverse_iterator it =str.crend()

For Exmaple:

str = "abc"

str.crend() => It points 1 element before  the first element (i.e one before a).

Approach

C++

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

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

    string ::const_reverse_iterator it = str.crend();

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

    return 0;
}


No comments:

Post a Comment