I was trying to implement my own "String" class.
I have written the class and the following error occurs.
1.When I create 2 String objects in main function only one string is getting inputted and the other completely ignored
object M is getting ignored..please mention why ..Code:#include <iostream>#include <cstring> #include <conio.h> using namespace std; enum{MAX=50}; class String { private: char S[MAX]; public: String() {S[0]='\0';} void getString(); void displayString(); }; void String::getString() { cout<<"Enter String :"<<endl; cin.get(S,MAX); } void String::displayString() { cout<<S<<endl; } int main() { String S,M; S.getString(); M.getString(); S.displayString(); M.displayString(); getch(); return 0; }
please provide the correct code if possible.