4

When do I use std::clog and std::cerr in c++?

What's difference between clog << "test" << endl; and cerr << "test" << endl;?

Does clog << "0" without endl print directly with no buffer?

joce
  • 9,624
  • 19
  • 56
  • 74
jiafu
  • 6,338
  • 12
  • 49
  • 73

1 Answers1

5

As per the documentation clog sends character output to the environment's standard logging stream, whereas cerr sends output to the error stream. These streams, as handled by the environment, can be made to point to different logging facilities, for example. In production code, one often needs to send more important logging events (noting errors and the like) to a specific logging facility - for off site storage or alerting for instance. With that in mind, start getting in the practice of using the lower severity clog function unless you really are noting an error condition!