主题:重载一个类的输入运算符报错了,,求助~!
下面是个简单的代码。。。无报错但运行时输入字符串后就提示:*******指令引用的内存********不能为wriiten第一次遇到这个问题,新手求助~!
#include <iostream.h>
class C
{public:
char * str;
friend istream & operator>>(istream &,C &);
};
istream & operator>>(istream & cin,C & c)
{cin>>c.str;return cin;}
int main()
{ C cc;
cc.str="aaa";
cout<<cc.str;
cout<<"ds";
cin>>cc;
cout<<cc.str;
return 0;
}
#include <iostream.h>
class C
{public:
char * str;
friend istream & operator>>(istream &,C &);
};
istream & operator>>(istream & cin,C & c)
{cin>>c.str;return cin;}
int main()
{ C cc;
cc.str="aaa";
cout<<cc.str;
cout<<"ds";
cin>>cc;
cout<<cc.str;
return 0;
}