














fprintf(stdout, "hello, %s", "world");
char buf[20];
sprintf(buf, "hello, %s", "world");
FILE *fp = stdin;
char str[20];
scanf("%s", str);
printf("size is %d", fp->_ftr - fp->_base);
全缓存只针对于文件,包括输出重定向到文件 1>log.txt 。
全缓存只有三种情况下会刷新缓存区:
fflush(stdout);
行缓存针对于控制台输入输出。比如 stdin 和 stdout 。
行缓存有四种情况,比全缓存多一种,即:
\n 换行符的时候会情空缓存不缓存的例子是 stderr 。
读写文件的例子有:
#include <perror.h>
FILE *fp = fopen(argv[1], 'r');
if(NULL == fp) {
perror("fail to open");
return -1;
}
while(1) {
ch = fgetc(fp);
if(EOF == ch)
break;
fputc(ch, stdout);
}
fread/fwrite
fseek
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。