Check out example codes for "use of strstr in c++". It will help you in understanding the concepts better.

Code Example 1

// CPP program to illustrate strstr() 
#include <string.h> 
#include <stdio.h> 
  
int main() 
{ 
    // Take any two strings 
    char s1[] = "Fun with STL"; 
    char s2[] = "STL"; 
    char* p; 
  
    // Find first occurrence of s2 in s1 
    p = strstr(s1, s2); 
  
    // Prints the result 
    if (p) { 
        strcpy(p, "Strings"); 
        printf("%s", s1); 
    } else
        printf("String not found\n"); 
  
    return 0; 
}

Code Example 2

#include <iostream>
#include <string.h>

using namespace std;
int main() {
   char str1[] = "Apples are red";
   char str2[] = "are";
   char *ptr;
   ptr = strstr(str1, str2);

   if(ptr)
   cout<<"Occurance of \""<< str2 <<"\" in \""<< str1 <<"\" is at position "<<ptr - str1 + 1;

   else
   cout<<"There is no occurance of \""<< str2 <<"\" in "<<str1;
   return 0;
}

Code Example 3

/* strstr example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="This is a simple string";
  char * pch;
  pch = strstr (str,"simple");
  strncpy (pch,"sample",6);
  puts (str);
  return 0;
}

Learn ReactJs, React Native from akashmittal.com