COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button
C++ LANGUAGE STANDARD LOG STREAM (CLOG)
The Standard Log Stream (clog)
The predefined object clog is an instance of ostream class.
The clog object is said to be attached to the standard error
device, which is also a display screen but the object clog is
buffered. This means that each insertion to clog could cause
its output to be held in a buffer until the buffer is filled
or until the buffer is flushed.
The clog is also used in conjunction with the stream insertion
operator as shown in the following example.
#include <iostream>
using namespace std;
int main( )
{
char str[] = "Unable to read....";
clog << "Error message : " << str << endl;
}
When the above code is compiled and executed,
it produces the following result:
Error message : Unable to read....
You would not be able to see any difference in cout, cerr
and clog with these small examples, but while writing and
executing big programs the difference becomes obvious.
So it is good practice to display error messages using cerr
stream and while displaying other log messages then clog should be used.
No comments:
Post a Comment