C++摘要——什么时候使用std::cout,什么时候用std::cerr

来源:互联网 发布:淘宝全年销售额 编辑:程序博客网 时间:2024/05/17 08:13

What is the difference between cout, cerr, clog of iostream header in c++? When to use which one?

stdout and stderr are different streams, even though they both refer to console output by default. Redirecting (piping) one of them (e.g. program.exe >out.txt) would not affect the other.

Generally, stdout should be used for actual program output, while all information and error messages should be printed to stderr, so that if the user redirects output to a file, information messages are still printed on the screen and not to the output file.

以前关于什么时候用cout, 什么时候用cerr有比较大的随意性质,总结一下:显式print 一定要用std::cout, 其余情况,用情况主要用std::cerr

class ClassA

{

void print()

{

        std::cout<<....

}

};



1 0
原创粉丝点击