65,113
社区成员
发帖
与我相关
我的任务
分享
上面代码有点小错误~~ 更正之~
class Vector2 {
int x,y;
....
friend std::ostream& operator<<(std::ostream& os, const Vector2& rhs) {
os<<"Vector2( "<<rhs.x<<" , "<<rhs.y<<" )";
return os;
}
};
再普通一点的用处大概就是可以把自己的对象用流的方法输出
class Vector2 {
int x,y;
....
friend std::ostream& operator<<(std::ostream& os, const Vector2& rhs) {
os<<"Vector2( "<<x<<" , "<<y<<" )";
return os;
}
};
这样就可以
void f() {
Vector2 v1,v2;
std::cout<<v1<<std::endl;
std::cout<<v2<<std::endl;
}
display( cout )<<"aaaa"<<"bbbb"<<endl;
display(cout)<<"world!";