I'm trying to make custom string class,
everything is working fine in this but when i take input then it is not printing any line after that it just ends the program
#include<bits/stdc++.h>
using namespace std;
class String
{
char *ch; // buffer
unsigned int len; // to store the length
public:
// default constructor
String() : ch(nullptr) , len(0){};
// parametrized constructor
String(const char *str)
{
len = strlen(str+1);
ch = new char[len+1];
strcpy(ch,str); // (to , from)
}
// copy constructor
String(const String& str)
{
this->ch = str.ch;
len = strlen(ch+1);
}
// assignment operator overloading
String &operator=(String str)
{
if(this->ch != str.ch)
{
Swap(*this,str);
}
return *this;
}
void Swap(String &a, String &b){
std::swap(a.ch,b.ch);
std::swap(a.len,b.len);
}
friend ostream &operator<<(ostream &out , const String &str);
friend istream &operator>>(istream &in , String &str);
};
ostream &operator<<(ostream &out , const String &str)
{
out<<str.ch;
return out;
}
istream &operator>>(istream &in , String &str)
{
in>>str.ch;
return in;
}
int main()
{
String myString = "hello";
// cin>>myString;
cout<<myString<<endl;
String sty ;
sty = myString;
cout<<sty<<endl;
String hup;
cin>>hup;
cout<<hup<<endl;
}