What is the difference between them? (if any)
What is the difference between them? (if any)
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Here is a good page to answer that.
http://www.cs.ust.hk/~martin/01Sprin...n_iostream.htm
Sent from my iPadŽ
cerr is an error stream commad
cout is an input stream command both are found in iostream
cout is an input stream?
I gues cin is an output stream then?
hmm...
Sent from my iPadŽ
cerr and cout are both for output.
cerr is especialy for error messages.
I knew it even before opening this thread.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Then what was the point of the thread?
Sent from my iPadŽ
He just wanted to see if we knew as well.Originally Posted by SlyMaelstrom
No, what I don't know is the difference in their functionality. Why there are different objects for normal text output and error output.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
I thought Sly hit that already.Originally Posted by siavoshkcDid you follow this link?Originally Posted by SlyMaelstromThe difference between cout and cerr is illustrated clearly during output redirection (forget about it? Take a look here!). Only data output by cout are redirected to the file. Data output by cerr are still displayed in the terminal. This is usually what we want, because error messages should not mix with normal output which are redirected to a file in this example.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
I read that and concluded that it makes no difference in output to screen. And if we have a fstream object then cerr will output the text to screen instead of file, am I right?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
How about an example?Running it without redirection:Code:#include <iostream> using std::cout; using std::cerr; int main() { for ( int i = 0; i < 10; ++i ) { cout << "cout: i = " << i << '\n'; if ( i & 1 ) { cerr << "cerr: i = " << i << '\n'; } } return 0; }Redirecting stdout:Code:C:\Test\GnuC>Cpp\myapp.exe cerr: i = 1 cerr: i = 3 cerr: i = 5 cerr: i = 7 cerr: i = 9 cout: i = 0 cout: i = 1 cout: i = 2 cout: i = 3 cout: i = 4 cout: i = 5 cout: i = 6 cout: i = 7 cout: i = 8 cout: i = 9The contents of output.txt:Code:C:\Test\GnuC>Cpp\myapp.exe > output.txt cerr: i = 1 cerr: i = 3 cerr: i = 5 cerr: i = 7 cerr: i = 9Redirecting stderr:Code:cout: i = 0 cout: i = 1 cout: i = 2 cout: i = 3 cout: i = 4 cout: i = 5 cout: i = 6 cout: i = 7 cout: i = 8 cout: i = 9The contents of errors.txt:Code:C:\Test\GnuC>Cpp\myapp.exe 2> errors.txt cout: i = 0 cout: i = 1 cout: i = 2 cout: i = 3 cout: i = 4 cout: i = 5 cout: i = 6 cout: i = 7 cout: i = 8 cout: i = 9Code:cerr: i = 1 cerr: i = 3 cerr: i = 5 cerr: i = 7 cerr: i = 9
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Aha, I didn't know about redirection and when I pressed the link(in sly's link) it was about makefile!!
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C