string rbegin() in C++

rbegin(): This function returns a read/write reverse iterator that points to 

the last character in the 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.rbegin()

For Example:

str = "abc"

str.rbegin() = > It returns iterator to last character (i.e 'c')

Approach

C++

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

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

    string ::reverse_iterator it = str.rbegin();
   
    cout << *it << "\n";
    return 0;
}


No comments:

Post a Comment