cout简单实现

#include <stdio.h>

class MyOut
{
public:
    const MyOut& operator<<(int value) const
    {
        printf("%d", value);
        return *this;
    }

    const MyOut& operator<<(char *value) const
    {
        printf("%s", value);
        return *this;
    }
};

MyOut out;

int main()
{
    char str[] = "HelloWorld\n";
    int a = 10;
    out << str << a;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_35338800/article/details/83099771