[問題] operator<< (輸出建構子不知道怎樣輸出)
class a
{
friend ostream &operator<<(ostream out,const a *f)
{
out<<f->bo<<","<<f->co<<endl;
return out;
}
public:
a(int b,int c)
{
bo=b;
co=c;
}
private:
int bo,co;
};
int main(int argc, char *argv[])
{
a t(1,2);
cout<<t; ????????????????請問我要如何才能將t印出來為1,2
system("PAUSE");
return EXIT_SUCCESS;
}
忙煩大大們幫忙一下
我這個問題卡很久了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.224.74.39
※ 編輯: beckon 來自: 125.224.74.39 (05/18 22:59)
推
05/18 23:01, , 1F
05/18 23:01, 1F
→
05/18 23:05, , 2F
05/18 23:05, 2F
推
05/18 23:40, , 3F
05/18 23:40, 3F
十分感謝J大的幫忙
我將程式改成
friend ostream &operator<<(ostream &out,const a &f)
{
out<<f.bo<<" "<<f.co<<endl;
return out;
}
終於可以輸出
※ 編輯: beckon 來自: 125.224.74.39 (05/18 23:59)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章