custom stream manipulator for class

前端 未结 4 1350
情话喂你
情话喂你 2020-12-20 10:44

I am trying to write a simple audit class that takes input via operator << and writes the audit after receiving a custom manipulator like this:

class C         


        
4条回答
  •  隐瞒了意图╮
    2020-12-20 11:28

    Wouldn't this

    class CAudit
    {
    public:
        template< typename T >
        CAudit& operator<<( const T& data )
        {
            audittext << data;
            return *this;
        }
    
        class write {};
    
        void operator<<( const write& data )
        {
            /* whatever */
        }
    
    private:
        std::stringstream audittext;
    };
    

    do what you want?

提交回复
热议问题