Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: C++
Expertise: All
Jul 23, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Understanding File Descriptors

When a program opens a file, the operating system returns a corresponding file descriptor that the program refers to in order to process the file. A file descriptor is a low positive integer. The first three file descriptors (0,1, and 2,) are associated with the standard input (stdin), the standard output (stdout), and the standard error (stderr), respectively. Thus, the function scanf() uses stdin and the function printf() uses stdout. You can override the default setting and re-direct the process's I/O to different files by using different file descriptors:

  #include <cstdio>
  fprintf(stdout, "writing to stdout"); //write to stdout instead of a physical file
Danny Kalev
Thanks for your registration, follow us on our social networks to keep up-to-date