C++ String rfind() function
Last Updated : 17 Mar 2025
This function is used to find the string for the last occurrence of the sequence specified by its arguments.
Syntax
Consider a string 'str' and key string 's'. Syntax would be:
Parameter
str : str is a string object which is used in searching.
pos : It defines the position of the last character at which to start searching.
n : Number of characters to be considered in searching
ch : Character value to be searched for.
Example 1
Let's see this simple example.
Output:
Example 2
Let's see an another simple example by passing character value.
Output:
Example 3
Let's see this example when position pos is mentioned in a parameter.
Output:
Example 4
Let's see this example when number of characters to match is specified by its arguments.
Output: