How to see if one string contains another string?

Write a program which contains a class named String (please take care of the case). The class should be capable of holding a string containing more than one word.?

  • The class should at least have a parametric constructors by which we are going to supply a sentence at run time. Class string should be defined in this way that the following statement should be executed with their proper output. String str1; //string with length 0 String str2; cin>>str2; // to print the char elements of str2; (Don’t use any string library function for the any purpose) You are free to add any C++ concepts, any other data members, member functions and constructors you think are necessary to solve the problem.

  • Answer:

    #include<iostream> #define MAXLEN 2000 using namespace std; class String{     char *s;     unsigned int length;     public:     String(){         s=new char[MAXLEN];         length=0;     }         unsigned int len(){         return length;     }     friend ostream& operator<< (ostream &out,String ob){         out<<ob.s;         return out;     }     friend istream& operator>> (istream &in,String &ob){         in.get(ob.s,MAXLEN);         for(int i=0;ob.s[i]!='\0';i++)             ob.length++;         in.get();         return in;     } }; int main(){     String a;     cin>>a;     cout<<"You Entered: "<<a;     cout<<"\nLength: "<<a.len();    } Output: Hello World You Entered: Hello World Length: 11

Jignesh Jain at Quora Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.