#include <iostream>
using namespace std;
class Fruit //定義壹個類,名字叫Fruit
{
string name; //定義壹個name成員
string colour; //定義壹個colour成員
public:
friend istream& operator>>(istream&,Fruit&); //必須要聲明為友元啊,不然怎麽輸入啊
friend ostream& operator<<(ostream&,const Fruit&); //同理
void print() //定義壹個輸出名字的成員print()
{
cout<<colour<<" "<<name<<endl;
}
Fruit(const string &nst = "apple",const string &cst = "green"):name(nst),colour(cst)
{
} //構造函數
~Fruit()
{
}
};
ostream& operator<<(ostream &out,const Fruit &s) //我是輸出操作符的重載
{
out<<s.colour<<" "<<s.name;
return out;
}
istream& operator>>(istream& in,Fruit &s) //我是輸入操作符的重載
{
in>>s.colour>>s.name;
if(!in)
cerr<<"Wrong input!"<<endl;
return in;
}
int main()
{
Fruit apple;
cin >>apple;
cout<<apple;
return 0;
}