Most used string functions in C++ with an example program !


 #include <iostream>

#include <cstring>
using namespace std;
int main (){
   char s1[80],s2[80];
   gets(s1);
   gets(s2);
   cout << strlen(s1) << " " << strlen(s2)<< endl;
   if(strcmp(s1,s2)){
    cout << "The Strings are equal"<<endl;
   }
   strcat(s1,s2);
   cout << s1 << endl;
   strcpy(s1,"This is a test.\n");
   cout << endl;
   cout << s1;
   cout << endl;
   if(strchr("hello",'e')){
    cout << "e is in hello"<<endl;
   }
   if(strstr("hi there","hi")){
    cout << "found hi"<<endl;
   }
    return 0;
}

Comments