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

后端 未结 7 1526
小蘑菇
小蘑菇 2020-12-07 08:32

I tried researching the difference between cout, cerr and clog on the internet but couldn\'t find a perfect answer. I still am not cle

相关标签:
7条回答
  • 2020-12-07 08:57

    Both cout and clog are buffered but cerr is un-buffered and all of these are predefined objects which are instances of class ostream. The basic use of these three are cout is used for standard input whereas clog and cerr is used for showing errors. The main point why cerr is un-buffered is may be because suppose you have several outputs in the buffer and an error exception is mentioned in the code then you need to display that error immediately which can be done by cerr effectively.

    Please correct me if I am wrong.

    0 讨论(0)
提交回复
热议问题