string find_first_not_of() in C++

find_first_not_of():Find position of a character not in C string. 

It returns index of first occurrence. Starting from __pos, searches forward for a 

character not contained in __s within this string. 

If found, returns the index where it was found. If not found, returns npos.

Parameters: 

__s – C string containing characters to avoid.

 __pos – Index of character to search from (default 0). 

Syntax:

str.find_first_not_of(__s , __pos)

For Example:

str = "abc"

str.find_first_not_of("b",1)=> It returns 2

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str = "abc";

    cout << str.find_first_not_of("b"1<< "\n";
    

    return 0;
}


No comments:

Post a Comment