C++日志异常到文件,输出不同
我想将一个异常记录到一个文件中,并将其发送到控制台。我的问题是我得到了不同的输出 void logstd::string str,std::异常e{ std::流错误文件; errorfile.openerrorlog.txt,std::ios::out | std::ios::app; errorfile在函数void logstd::string str,std::exception e中,创建异常的副本 将函数修改为void logstd::string&str、std::exception&e 获取此对象上的引用以保留相同的异常/消息,而不创建具有空白字段的新异常/消息C++日志异常到文件,输出不同,c++,exception,logging,C++,Exception,Logging,我想将一个异常记录到一个文件中,并将其发送到控制台。我的问题是我得到了不同的输出 void logstd::string str,std::异常e{ std::流错误文件; errorfile.openerrorlog.txt,std::ios::out | std::ios::app; errorfile在函数void logstd::string str,std::exception e中,创建异常的副本 将函数修改为void logstd::string&str、std::exceptio
这样做也可以提高性能。当然可以。生成文件输出的代码不同,只需编写e.what to cerr?使用std::cerr Ok,但为什么不使用e.what inside log函数呢?编辑:啊,可以,但您已将std::exception作为副本传递。请尝试更改函数t的参数o std::exception&e而不是std::exception e。它解决了您的问题吗?我这样做了。errorfile。如果您在理解它为什么工作时遇到困难并且对此感兴趣,请阅读多态调用,例如:
fuctionname()
bind: Address already in use
functionname()
std::exception