在Linux中,所有对设备和文件的操作都使用文件描述符来进行。

Linux中一个进程启动时,都会打开3个文件:标准输入、标准输出和标准出错处理。这三个文件分别对应文件描述符0、1、2。

 

在C语言中,在程序开始运行时,系统自动打开3个标准文件:标准输入、 标准输出、标准出错输出。通常这3个文件都与终端相联系。因此,以前我们所用到的从终端输入或输出都不需要打开终端文件。系统自定义了3个文件指针stdin、stdout、stderr,分别指向终端输入、终端输出和标准出错输出(也从终端输出)。

标准输入流:stdin

标准输出流:stdout

标准错误输出流:stderr

 


object
<cstdio>
FILE * stdin;

Standard input stream

freopen function.

stdout


object
<cstdio>
FILE * stdout;

Standard output stream

stderr


object
<cstdio>
FILE * stderr;

Standard error stream

freopen function.

perror


function
<cstdio>
void perror ( const char * str );

Print error message

Interprets the value of the global variable errno into a string and prints that string to stderr (standard error output stream, usually the screen), optionaly preceding it with the custom message specified in str.
errno is an integral variable whose value describes the last error produced by a call to a library function. The error strings produced by perror depend on the developing platform and compiler.
If the parameter str is not a null pointer, str is printed followed by a colon (:) and a space. Then, whether str was a null pointer or not, the generated error description is printed followed by a newline character ('\n').
perror should be called right after the error was produced, otherwise it can be overwritten in calls to other functions.

Parameters.

str
C string containing a custom message to be printed before the error message itself.
If it is a null pointer, no preceding custom message is printed, but the error message is printed anyway.
By convention, the name of the application itself is generally used as parameter.

相关文章:

  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2021-09-15
  • 2021-11-11
相关资源
相似解决方案