zoukankan      html  css  js  c++  java
  • setvbuf

    函数名: setvbuf

    用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
    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
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    #include <stdio.h>
     
    int main()
    {
        FILE *input, *output;
        char bufr[512];
        input = fopen("file.in""r+b");
        output = fopen("file.out""w");
        /* set up input stream for minimal disk access,
        using our own character buffer */
        if (setvbuf(input, bufr, _IOFBF, 512) != 0)
            printf("failed to set up buffer for input file ");
        else
            printf("buffer set up for input file ");
        /* set up output stream for line buffering using space that
        will be obtained through an indirect call to malloc */
        if (setvbuf(output, NULL, _IOLBF, 132) != 0)
            printf("failed to set up buffer for output file ");
        else
            printf("buffer set up for output file ");
        /* perform file I/O here */
        /* close files */
        fclose(input);
        fclose(output);
        return 0;
    }
  • 相关阅读:
    ThinkPHP5如何修改默认跳转成功和失败页面
    layer:web弹出层解决方案
    js插件---video.js如何使用
    【Leetcode】Search a 2D Matrix
    tableView 短剪线离开15像素问题
    经Apache将tomcat转用80port这两个域名
    [Python 2.7] Hello World CGI HTTP Server
    《代码的第一行——Android》封面诞生
    MySQL汇总数据
    Windows移动开发(一)——登堂入室
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/4955894.html
Copyright © 2011-2022 走看看