小编div*_*a23的帖子

制作自定义cout时出错

我正在尝试创建一个自定义cout类,当我尝试运行不处理链接的代码版本(out <<"one"<<"two")时,将文本输出到控制台输出和日志文件,它工作正常,但是当我试图让它处理链接时,它给了我"这个操作员功能的参数太多".我错过了什么?

class CustomOut
{
    ofstream of;

public:
   CustomOut()
   {
     of.open("d:\\NIDSLog.txt", ios::ate | ios::app);
   }

   ~CustomOut()
   {
     of.close();
   }

   CustomOut operator<<(CustomOut& me, string msg)
    {
    of<<msg;
    cout<<msg;

    return this;
}};
Run Code Online (Sandbox Code Playgroud)

c++

3
推荐指数
1
解决办法
103
查看次数

标签 统计

c++ ×1