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