Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
#include<iostream>
#include<string>
using namespace std;
int strStr(string haystack, string needle) {
int a = haystack.size();
int b = needle.size();
if(!b) return 0;
for(int i = 0; i < a - b + 1; i++)
{
int j = 0;
for(; j < b; j++)
{
if(haystack[i + j] != needle[j]) break;
}
if(j == b) return i;
}
return -1;
}
int main()
{
string a,b;
cin >> a >> b;
int num = strStr(a,b);
cout << num << endl;
return 0;
}