Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap