What is stderr? Where Can I Find It? What is cerr?

Apr 18, 2009 at 1:18am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// cerr example
//
#include<iostream>
#include<fstream>

void main ( )
{
  using namespace std;

  // open the file "file_name.txt"
  // for reading
  ifstream in("file_name.txt");
  
  // output the all file to stdout
  if ( in ) 
    cout << in.rdbuf(); 
  else
    // if the ifstream object is in a bad state
    // output an error message to stderr
    cerr << "Error while opening the file" << endl;  
}


// if the ifstream object is in a bad state
// output an error message to stderr


Where is stderr? Where cerr output the error message? How can i grab it since its not printed to a place that a programmer specified such as file or screen...

Note: i got this code from the internet from a good source. I did not test it yet
Apr 18, 2009 at 4:00am
cerr is basically like cout, although it seems like it was red colored usually.
Apr 18, 2009 at 4:32am
stderr is include in the <cstdio> header.

cerr is normal gray colored text on my computer.
Last edited on Apr 18, 2009 at 4:32am
Apr 22, 2009 at 6:03am
Thanks....
Topic archived. No new replies allowed.