strpos in cpp code example

Example 1: string in cpp

// Include the string library
#include <string>

// Create a string variable
string greeting = "Hello";

Example 2: use of strstr in c++

/* 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;
}

Example 3: strstr

const char * strstr( const char * fullString, const char * substring );    // C++ (<cstring>)
      char * strstr(       char * fullString,       char * substring );    // C (<string.h>)

Tags:

C Example