今天在做C++ Primer习题的14.11时,印象中应该挺简单的一题,结果却费了很长时间。
类定义:
typedef string Date;
class CheckoutRecord{
public:
CheckoutRecord(){book_id=-1;}
friend ostream& operator<<(ostream &os,const CheckoutRecord &obj);
friend istream& operator>>(istream &in,CheckoutRecord &obj);
private:
double book_id;
string title;
Date date_borrowed;
Date date_due;
pair<string,string> borrower;
vector<pair<string,string>*>wait_list;
};
重载输出操作符很简单:
ostream& operator<<(ostream &os,const CheckoutRecord &obj)
{
os<<"Book ID:"<<obj.book_id<<endl;
os<<"Title :"<<obj.title<<endl;
os<<"Data borrowed:"<<obj.date_borrowed<<endl;
os<<"Date due :"<<obj.da