Dotcpp  >  编程教程  >  stdio.h头文件  >  C语言setbuf()函数:把缓冲区与流相联

C语言setbuf()函数:把缓冲区与流相联

点击打开在线编译器,边学边练

函数名: setbuf

头文件:<stdio.h>

函数原型: void setbuf(FILE *steam, char *buf);

功 能: 把缓冲区与流相联,实现操作缓冲区时直接操作了文件流的功能

参数:FILE *stream  为要处理的流

          char *buf     为要处理的缓冲区

返回值: 没有返回值 


程序例:  将标准文件流指定缓冲区outbuf

#include<stdio.h>

char outbuf[BUFSIZ];

int main(void){

   setbuf(stdout, outbuf);  //将缓冲区与流相关联

   puts("This is a test of buffered output.\n\n");  //将字符写入缓冲区

   puts("This output will go into outbuf\n");

   puts("and won't appear until the buffer\n");

   puts("fills up or we flush the stream.\n");

   fflush(stdout);  //刷新缓冲区

   return 0;

}

运行结果

This is a test of buffered output.
 
 
This output will go into outbuf
 
and won't appear until the buffer
 
fills up or we flush the stream.



本文固定URL:https://www.dotcpp.com/course/537

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)