首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

再问ostream(有例子)解决方法

2012-03-28 
再问ostream(有例子)昨天发了一帖询问ostream类型,结果没什么人给出详细的解答,那么请大家给我看看这个程

再问ostream(有例子)
昨天发了一帖询问ostream类型,结果没什么人给出详细的解答,那么请大家给我看看这个程序里的ostream,具体是怎么回事
为什么我单独定义   ostream   b;就不对
class   Rectangle
{
int   width,hight;
friend   ostream   &   operator < <(ostream   &out,const   Rectangle   &rhs)
{
out < < "[ " < <rhs.width < < ", " < <rhs.hight < < "] ";
return   out;
}
public:   Rectangle(int   _w,   int   _h):width(_w),hight(_h){}
};

[解决办法]
有什么不对的呢,楼主的的定义完全正确啊,不会使用?
mymtom@fc6:src/csdn/cpp/ios$ cat op.cpp
#include <iostream>
using namespace std;

class Rectangle
{
int width,hight;
friend ostream & operator < <(ostream &out,const Rectangle &rhs)
{
out < < "[ " < <rhs.width < < ", " < <rhs.hight < < "] ";
return out;
}
public: Rectangle(int _w, int _h):width(_w),hight(_h){}
};

int main(void)
{
Rectangle rect(16, 9);

cout < < rect < < endl;
return 0;
}

mymtom@fc6:src/csdn/cpp/ios$ make op
g++ op.cpp -o op
mymtom@fc6:src/csdn/cpp/ios$ ./op
[16,9]
mymtom@fc6:src/csdn/cpp/ios$

热点排行