Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class String
- {
- private:
- char sentence[20]{};
- public:
- String()
- {
- strcpy(sentence, "");
- }
- void putSentence()
- {
- cout << "Enter a sentence" << endl;
- // sentence = new char[20];
- cin >> sentence;
- }
- String& operator=(const String& t)
- {
- String temp{t};
- strcpy((*this).sentence, temp.sentence);
- return *this;
- }
- void outputSentence()
- {
- cout <<"Sentence is" <<endl;
- cout <<"\t"<<sentence << endl;
- }
- };
- int main()
- {
- String sentence1, sentence2;
- sentence1.putSentence();
- sentence1.outputSentence();
- sentence2.putSentence();
- sentence2.outputSentence();
- sentence1 = sentence2;
- sentence1.outputSentence();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement