This function scans the string to find the final character that matches any of the characters specified within the string.
Syntax
Consider two strings str1 and str2. The syntax is as follows:
str1.find_last_of(str2);
Parameters
str : str is the string to be used in searching.
The position parameter specifies the starting point for the search operation.
n : The quantity of characters that serve as identifiers for the characters to be searched for.
The 'ch' parameter specifies the character to search for.
Return value
It provides the index of the initial character that differs.
Examples 1
Let's see the simple example.
#include<iostream>
using namespace std;
int main()
{
string str = "I love India";
cout<< "String contains :" << str <<'\n';
cout<< str.find_last_of("love");
return 0;
}
Output:
String contains : I love India
5
Examples 2
Let's explore a basic example where the specified starting position for the search is provided.
#include<iostream>
using namespace std;
int main()
{
string str = "C++ Tutorial";
cout<< "String contains :" << str <<'\n';
cout<< str.find_last_of("Tutorial",3);
return 0;
}