重载<< 实现流输出

来源:互联网 发布:数据执行保护删除不掉 编辑:程序博客网 时间:2024/06/06 03:24

class test_end_l
{

}endl;
class test
{
public:
    test& operator << (int i);
    test& operator << (test_end_l end_l);
};

test& test::operator << (int i)
{
    printf("%d",i);
    return *this;
}
test& test::operator << (test_end_l end_l)
{
    printf("/n");
    return *this;
}

 

 

int main(int argc, char* argv[])
{
    test t;
    t<<(1)<<(2);
    t<<endl;
    t<<(1)<<(2)<<endl;
 return 0;
}