string rfind() in C++

rfind(): This function finds the last position of a character in the string.

This function returns the index of the last occurrence. 

Starting from __pos searches backward for __c.

 within this string. If found, returns the index where it was found. 

If not found, returns npos.

 Parameters: 

__c – Character to locate. 

__pos – Index of character to search back from (default end). 

Syntax:

str.rfind(__c, __pos)

For Example:

str = "abc"

str.rfind('a')

Approach

C++

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

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

    cout << str.rfind('a'<< "\n";

    return 0;
}

No comments:

Post a Comment