#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
class
deal_string
{
public:
deal_string(int n=50):number(n)
//默认构造 和 含参构造 函数; 默认初始化分配50个字节;
{
string = new char[ 50 ];
}
deal_string(char * str)
{
number= strlen(str) + 1;
string= new char[ number ];
strcpy(string,str);
cout<<"ok1"<<endl;
}
deal_string(deal_string & t)
//拷贝构造函数;
{
for(int i=0; i<t.number; i++)
string[i] = t.string[i];
number = t.number;
cout<<"ok3"<<endl;
}
~deal_string()
{
delete
[]string;
}
char * string;
unsigned number;
//对象不可随意调用private中的成员;
private:
friend deal_string operator +(deal_string & t1,deal_string & t2);
//将两个对象中的string连接在一起;
friend ostream & operator <<(ostream
& cout, const deal_string &a);
friend istream & operator >>(istream & cin,deal_string &b);
//重载 << ,>> 运算符
};
int main()
{
deal_string a, b;
cin>>a>>b;
deal_string d ;
d = a + b ;
cout<<a<<"\t"<<endl;
cout<<d;
return 0;
}
deal_string operator + (deal_string & t1, deal_string & t2)
{
deal_string temp;
strcpy(temp.string,t1.string);
strcat(temp.string,t2.string);
return deal_string(temp.string );
}
ostream & operator <<(ostream & cout,const deal_string &a)
{
cout<<a.string<<endl;
return cout;
}
istream & operator >>(istream & cin,deal_string & b)
{
cin>>b.string;
return cin;
}