我正在尝试创建一个自定义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++ ×1