C++ cout with prefix

后端 未结 4 1652
醉话见心
醉话见心 2021-01-07 14:15

I want a ostream with a prefix at the beginning of every line redirected on cout; I try this:

#include 
#include 
class paralle         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 14:47

    Your output operator is returning a reference to the base class (std::ostream), which means that the next call to operator << will not use your implementation.

    Changing your output operator to this should fix your problem:

    template 
    parallel_cout& operator<< (const T& val)
    {
        out << "prefix " << val;
        return *this;
    }
    

提交回复
热议问题