C++ String crbegin
The crbegin function stands for 'reverse beginning'. This function references to the last character of the string.
Syntax
Consider a string str. Syntax would be:
Example
str.crbegin();
Parameter
This function does not contain any parameter.
Return value
This function returns the constant iterator pointing to the last character of the string.
Example 1
Let's see the simple example of crbegin function:
Example
#include<iostream>
using namespace std;
int main()
{
string str =?Lotus Flower?;
for(auto i=str.crbegin();i!=str.end();i++)
{
cout<<*I;
}
return 0;
}
Output:
Output
rewolF sutoL
This example shows how to reverse the string using crbegin function.
Example 2
Example
#include<iostream>
using namespace std;
int main()
{
list<int> li(1,2,3,4,5);
for(auto i =li.crbegin();i!=end();i++)
{
cout<<*i;
}
return 0;
}
Output:
This example shows how to get the reverse list using crbegin function.