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

Generally you use std::cout for normal output, std::cerr for errors, and std::clog for “logging” (which can mean whatever you want it to mean).

The major difference is that std::cerr is not buffered like the other two.


In relation to the old C stdout and stderr, std::cout corresponds to stdout, while std::cerr and std::clog both corresponds to stderr (except that std::clog is buffered).

Leave a Comment