Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 自定义cout时出错_C++ - Fatal编程技术网

C++ 自定义cout时出错

C++ 自定义cout时出错,c++,C++,我试图创建一个自定义cout类,当我试图运行一个不处理链接的代码版本时,该类将文本输出到控制台输出和日志文件(out您需要一个甚至不会编译的成员运算符,您在返回此中的指针级别不匹配,其中返回类型为CustomOut@user1470033:您是否考虑过接受一个答案来解决您的问题? class CustomOut { ofstream of; public: CustomOut() { of.open("d:\\NIDSLog.txt", ios::ate | io

我试图创建一个自定义cout类,当我试图运行一个不处理链接的代码版本时,该类将文本输出到控制台输出和日志文件(out您需要一个甚至不会编译的成员
运算符,您在
返回此
中的指针级别不匹配,其中返回类型为
CustomOut
@user1470033:您是否考虑过接受一个答案来解决您的问题?
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;
}};
class CustomOut
{
  ...

  CustomOut& operator<<(string const& msg)
  {
    // Process message.
    f(msg);

    return *this;
  }
};
CustomOut out;
out << str_0 << str_i << ... << str_n;