《The C programming Language》中这样解释stdin,stdout
"The file pointers stdin and stdout are objects of type FILE *. They are constants, however, not variables, so it is not possible to assign to them."
stdout标准输出设备的文件句柄宏定义 printf其实就是fprintf的第一个参数设置为stdout 你可以理解为它就是一个文件,而这个文件和标准输出设备(屏幕)建立了某种关联,当数据写到这个文件里面的时候,屏幕就会通过既定的方式把你写进去的东西显示出来.在C程序中完全可以讲stdout当做一种文件结构来处理。
#include <stdio.h> int main(int argc,char *argv[]) { FILE *ifile; //FILE *ofile; char c; if(argc <= 1) { return 0; } else { if((ifile = fopen(*++argv,"r")) == NULL) { printf("cat the file %s erro.\n",*argv); return 0; } else { while((c = getc(ifile)) != EOF) { putc(c,stdout); } } } return 0; }
stdout,stdin浅析
最新推荐文章于 2023-01-12 11:45:04 发布