#include <iostream.h>
#include <string>
class mystring{
char * pstr;
int length;
public:
mystring(){
pstr=NULL;
length =0;}
mystring(char * p,int n){
pstr = new char[n];
pstr= strcpy(p,pstr);
}
~mystring(){delete[]pstr;}
mystring & operator = (const mystring & temp){
if(pstr!=NULL)
delete [] pstr;
length=temp.length;
pstr=new char[length+1];
strcpy(pstr,temp.pstr);
return *this;
}
friend ostream & operator<<(ostream & os,mystring & temp);
friend istream & operator>>(istream & is,mystring & temp);
};
ostream & operator<<(ostream & os,mystring & temp){
cout<<temp.pstr;
return os;
}
istream & operator>>(istream & is,mystring & temp){
char p[10000];
if((temp.pstr)!=NULL)
delete []temp.pstr;
cout<<"请输入字符串内容:"<<endl;
cin>>p;
temp.pstr=new char[strlen(p)+1];
strcpy(temp.pstr,p);
temp.length=strlen(p);
return is;
}
void main(){
mystring a,b;
cin>>a;
b=a;
cout<<"b="<<b<<endl;
}
有引用符不报错
没有引用符 报错了