How to override cout in C++?

前端 未结 9 1430
礼貌的吻别
礼貌的吻别 2020-12-07 02:47

I have a requirement, I need to use printf and cout to display the data into console and file as well. For printf I have

9条回答
  •  情深已故
    2020-12-07 03:45

    If you have another stream buffer, you can just replace std::cout's:

    std::cout.rdbuf(some_other_rdbuf);
    

    See http://en.cppreference.com/w/cpp/io/basic_ios/rdbuf.

提交回复
热议问题