zoukankan      html  css  js  c++  java
  • setvbuf

    setvbuf

      函数名: setvbuf

      功 能: 把缓冲区与流相关
      用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
      参数:stream :指向流的指针 ;
          buf      : 期望缓冲区的地址;
          type    : 期望缓冲区的类型:
            _IOFBF(满缓冲):当缓冲区为空时,从流读入数据。或者当缓冲区满时,向流写入数  据。
            _IOLBF(行缓冲):每次从流中读入一行数据或向流中写入一行数据。
            _IONBF(无缓冲):直接从流中读入数据或直接向流中写入数据,而没有缓冲区。
          size    :  缓冲区内字节的数量。
      注意:This function should be called once the file associated with the stream has already been opened but before any input or output operation has taken place.
      意思是这个函数应该在打开流后,立即调用,在任何对该流做输入输出前
    程序例:
     1 #include <stdio.h>
     2 int main(void)
     3 {
     4 FILE *input, *output;
     5 char bufr[512];
     6 input = fopen("file.in", "r+b");
     7 output = fopen("file.out", "w");
     8 /* set up input stream for minimal disk access,
     9 using our own character buffer */
    10 if (setvbuf(input, bufr, _IOFBF, 512) != 0)
    11 printf("failed to set up buffer for input file
    ");
    12 else
    13 printf("buffer set up for input file
    ");
    14 /* set up output stream for line buffering using space that
    15 will be obtained through an indirect call to malloc */
    16 if (setvbuf(output, NULL, _IOLBF, 132) != 0)
    17 printf("failed to set up buffer for output file
    ");
    18 else
    19 printf("buffer set up for output file
    ");
    20 /* perform file I/O here */
    21 /* close files */
    22 fclose(input);
    23 fclose(output);
    24 return 0;
    25 }

    参考:http://baike.baidu.com/link?url=jxeLxw7cLnX4Wx0HdbDHwC54lhoTmu7HWRs_aFVezv2fR5CqyHpfdY_dDdIgSW3w1j_RFW_mkxkTb0rzRhC3VK

  • 相关阅读:
    Java 窗口 绘制图形 #1
    支配树
    Tarjan算法
    Baby-step giant-step算法
    初等群论
    第七次java作业
    学习所用的开发环境
    第六次java作业
    第五次java作业
    第四次java作业
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3377855.html
Copyright © 2011-2022 走看看