跳到主要内容

重载读入读写运算

· 阅读需 1 分钟
//举例
struct Patient
{
string name;
int order;

bool operator <( const Patient &a )const
{
return order < a.order;
}

};

istream& operator >>( istream& is,Patient &patient )
{
is>>patient.name>>patient.order;
return is;
}

ostream& operator <<( ostream& os,const Patient &patient )
{
os<<patient.name<<" "<<patient.order<<"\n";
return os;
}