string find() in C++

find(): Find the position of a C string. It returns the index of the start of the

first occurrence. 

Starting from __pos, searches forward for the value of * __s within this string. 

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

Parameters:

 __s – C string to locate.

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

Syntax:

str.find(__s , __pos)

For Example:

str ="abcdef"

str.find("bc",0) => It returns 1.

Approach

C++

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

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

    cout << str.find("bc"0<< "\n";
    

    return 0;
}


No comments:

Post a Comment