Stdin, stdout, stderr reprinted

Source: Internet
Author: User

 

Stdin, stdout, stderr reprinted

09:55:00 | category:

C language | Tag:
| Large font size, medium/small subscription

* Standard input/output stream
# Include <stdio. h>

Extern file * stdin;
Extern file * stdout;
Extern file * stderr;

// Man
1. stdin
* 0;   // Standard file descriptor;
* Standard input stream;

2. stdout
* 1;
* Standard output stream;

3. stderr
* 2;
* Standard error output stream

 

+++ ++ (Extend)
1. // man

EachOf these symbols is a stdio (3) Macro of Type pointer to file,
 And can be used with functions like fprintf (3) or fread (3 ).

2. // csdn

Like stderr, stdout, stderr is a stream.
 Specifically:
 Stdin is a standard input stream. The default value is the keyboard,
 Stdout is a standard output stream. The default value is screen,
 Stderr is a standard error stream. Generally, the screen is set as the default,It can also be output to a file. 

3. // csdn

Stdin and stdout can be redirected to a file and stderr can be output to the screen;
 Therefore, do not use printf ("error"), fprintf (stdout, "Error ");
 This is because the message may be redirected to a file;
 Use fprintf (stderr, "Error ");
                
4. // Baidu Knows

Fprintf (stderr, "can't open it! \ N ");
Fprintf (stdout, "can't open it! \ N ");
Printf ("can't open it! \ N ");

These three statements have different effects. What are the differences?

Questioner: assume it is still true if-the trial period is second-level.
Best Answer

Source: (http://blog.sina.com.cn/s/blog_5f283b430100hn11.html)-stdin, stdout, stderr _ raptors _ Sina Blog

There are differences.
Stdout-the standard output device (printf ("..") is the same as stdout.
Stderr -- standard error output device
The two are output to the screen by default.
However, if you use the redirection standard to output data to a disk file, you can see the difference between the two. Stdout outputs to the disk file, and stderr is on the screen.

For example:
My.exe
Can't open it!
Can't open it!
Can't open it!

Export data to the export file tmp.txt
My.exe> tmp.txt
Can't open it!

Use Type to view the content of tmp.txt:
Type tmp.txt
Can't open it!
Can't open it!

5. // csdn

In C, the error handling functions include assert, clearerr, dosexterr, ferror, harderr, hardresume, matherr, perror, strerror.
 Example of strerror
   # Include <Stdio. h>
   # Include <Errno. h>
   Int Main ( Void )
     {
        Char * Buffer;
      
        Buffer = Strerror (enoent );
       
         Printf (" Error Is : % S ", buffer );
         Return 0;
     }  
 Running result:
   The Error Is : No Such File Or Directory
     

6. // Baidu Knows

Excuse me:
When the file pointer FP returns a null value and an error message is prompted,
   Why is fprintf (stderr, "error") better than printf ("error?
   The more detailed the better! Thank you!

   Questioner: wave_dan-scholar Level 2
   Best Answer

   Generally, the results of the two statements are the same and there is no difference between them. Only the following situations are different:

   Labels:
   A.exe> a.txt

   In this situation, if you use printfto output error information, it will be saved to the.txt file. If you use fprintf to output an error, it will be displayed on the screen.

7. csdn

Stderr, stdout
 All output data to the terminal.
    
   Stderr, which can be output during compilation.
   Stdout must be at the runtime.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/minothing/archive/2009/10/29/4744640.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.