您的位置:首页 > 编程语言 > C语言/C++

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

2014-10-23 12:49 190 查看


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<<....

}

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: