新人求助 关于重载运算符的问题
#include <iostream.h>class merchandise{
public:
merchandise()
{
no=0;
price=0.0;
}
~merchandise()
{
no=0;
price=0.0;
}
friend istream& operator>>(istream& in,merchandise& s);
friend ostream& operator<<(ostream& out,merchandise& s);
private:
int no;
char *name;
double price;
};
istream& operator>>(istream &in,merchandise &s)
{
cout<<"请输入商品编号";
cin>>s.no;
cout<<"请输入商品名称";
cin>>s.name;
cout<<"请输入价格";
cin>>s.price;
return cin;
}
ostream&operator<<(ostream &out,merchandise &s)
{
cout<<"输出结果为";
cout<<endl;
cout<<"编号";
cout<<s. no;
cout<<endl;
cout<<"名称";
cout<<s.name;
cout<<"endl";
cout<<"价格";
cout<<s.price;
cout<<endl;
return cout;
}
int main()
{
merchandise mer;
cin>>mer;
cout<<mer;
return 0;
}在输入商品名称的时候会出错!