#include <iostream>
#include <cstring>
using namespace std;
class my_string
{
private:
char *str;
int len;
public:
//无参构造函数
my_string()
{
len=0;
str=NULL;
}
// ~my_string(){}
//有参构造函数
my_string(char *s)
{
// len=my_size();
this->str=new char[64];
strcpy(str,s);
len=my_size();
}
//my_string()
//拷贝构造
my_string(const my_string & O)
{
this->len=O.len;
str=new char[len+1];
strcpy(this->str,O.str);
}
//拷贝赋值
my_string& operator=(const my_string& R)
{ if(this != &R)
{
this->len=R.len;
this->str=new char[len+1];
strcpy(this->str,R.str);
}
return *this;
}
//判空
bool my_empty()
{
return str==NULL?true:false;
}
//求长度
int my_size()
{
return strlen(str);
}
//转化为c风格字符串
char *my_str()
{
return str;
}
void display()
{
cout<<"str="<<my_str()<<endl;
cout<<"size="<<my_size()<<endl;
cout<<"empty?"<<(my_empty()?"yes":"no")<<endl;
}
};
int main()
{
my_string s1("helloworld");
my_string s2(s1);
cout<<"s1:"<<endl;
s1.display();
cout<<"s2:"<<endl;
s2.display();
return 0;
}