This function is employed to scan the string for the initial character that differs from any of the characters defined in the string.
Syntax
Consider two strings referred to as str1 and str2. The syntax is as follows:
str1.find_first_not_of(str2);
Parameters
str : str is the string to be used in searching.
It specifies the starting position for the search operation.
n : The quantity of characters that serve as identifiers for the characters to be searched for.
It specifies the character that needs to be located.
Return value
It provides the index of the initial character that differs.
Example 1
Lets see the simple example.
#include<iostream>
using namespace std;
int main()
{
string str = "Hello";
cout<< "String contains :" << str <<'\n';
cout<< str.find_first_not_of("Hllo");
}
Output:
String contains : Hello
1
Example 2
Let's examine a straightforward example where the specified starting position for the search is provided.
#include<iostream>
using namespace std;
int main()
{
string str = "Welcome to the javacpptutorial";
cout<< "String contains :" << str <<'\n';
cout<< str.find_first_not_of("COME",3);
return 0;
}
Output:
String contains : Welcome to the javacpptutorial
3