Objectives :

  • File name: compare_substr_Cstrstr1.cpp
    The function of C/cstdio library, strstr(chstr1, 'e'), finds the first occurrence of  a substrings in a string;
    The function of C++ string class, str1.substr (8,13);, returns a substring of a  string.
  • Code : compare_substr_Cstrstr1.txt

Step: 1 Create a source file.

Step: 2 Edit and save Source file

Step: 3 Runtime Views:

Step: Brief Discussion:

In the illustration, shown below, the function strncpy(----) of C/cstrlib library, trims the length of a string, from left to right. In this case a pointer/array, sets the beginning of a target sequence or string.  With string class of C++ language, string::substr(---) function allows you to select the length of a substring.