setbuf()函数setbuf
语法:
1 2 |
?? #include <stdio.h> ?? void setbuf( FILE *stream, char *buffer ); |
setbuf()函数设置stream(流)使用buffer(缓冲区),如果buffer(缓冲区)是null,关闭缓冲. 如果使用非标准缓冲尺寸, 它应该由BUFSIZ字符决定长度.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <stdio.h> char outbuf[BUFSIZ];//必须是BUFSIZ,否则存在缓冲溢出可能 int main(void) { /* 将outbuf与stdout输出流相连接 */ setbuf(stdout,outbuf); /* 向stdout中放入一些字符串 */ puts("This is a test of buffered output.");//体现stdout的行缓冲性质 fprintf(stdout,"hello world."); /*刷新流*/ fflush(stdout); /* 以下是outbuf中的内容 */ puts(outbuf); return 0; } |