String Find First Not Of Function - C++ Programming Tutorial
C++ Course / Strings / String Find First Not Of Function

String Find First Not Of Function

BLUF: Mastering String Find First Not Of Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: String Find First Not Of Function

C++ is renowned for its efficiency. Learn how String Find First Not Of Function enables low-level control and high-performance computing in the tutorial below.

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:

Example

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.

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 examine a straightforward example where the specified starting position for the search is provided.

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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience