String Find First Not Of Function

This function is used to search the string for the first character that does not match any of the characters specified in the string.

Syntax

Consider two strings str1 and str2. Syntax would be :

Example

str1.find_first_not_of(str2);

Parameters

str : str is the string to be used in searching.

pos : It defines the position at which to start the search.

n : Number of characters identifying characters to be searched for.

ch : It defines the character which is to be searched

Return value

It returns the position of the first character that does not match.

Example 1

Lets see the simple example.

Example

#include<iostream>
using namespace std;
int main()
{
string str = "Hello";
cout<< "String contains :" << str <<'\n';
            cout<< str.find_first_not_of("Hllo");
           }

Output:

Output

String contains : Hello
1

Example 2

Let's see the simple example when the position at which to start the search is specified.

Example

#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:

Output

String contains : Welcome to the javacpptutorial
3

Input Required

This code uses input(). Please provide values below: