本文介绍了输出到2个流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序输出到cout,我也希望它输出到LOG文件。

有一个简单的方法吗?


弗雷泽。

My program outputs to cout and I want it to output to a LOG file as well.
Is there a simple way to do that?

Fraser.

推荐答案




这个简单的方法怎么样 -

std :: ofstream out1(" xxx.log");

.. ..

std :: cout<< 记录和打印的东西;

out1<< 记录和打印的东西;


您也可以使用Macro技巧来完成这项工作,例如 -


#define PRINT (xxx)std :: cout<< 记录和打印的东西; \

out1<< 记录和打印的东西;


int main()

{

//...

PRINT(要打印的东西);


}


-Sharad



How about this simple way -
std::ofstream out1("xxx.log");
....
std::cout << "Something to log and print";
out1 << "Something to log and print";

You could also use Macro trick to get this done, something like -

#define PRINT(xxx) std::cout << "Something to log and print"; \
out1 << "Something to log and print";

int main()
{
//...
PRINT ("Something to print");

}

-Sharad





应该是 -


#define PRINT(xxx)std :: cout<< XXX; \

out1<< xxx;



Should be --

#define PRINT(xxx) std::cout << xxx; \
out1 << xxx;



这篇关于输出到2个流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 10:07