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

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
cerr is basically like cout, although it seems like it was red colored usually.
stderr is include in the <cstdio> header.

cerr is normal gray colored text on my computer.
Last edited on
Thanks....
Topic archived. No new replies allowed.