85.缓冲区设置

满缓冲,满了再写
行缓冲,一行就写
无缓冲
默认的情况,操作系统帮你管理缓冲区
自己管,
#define _IOFBF 0x0000 full 缓冲区满了再干活
#define _IOLBF 0x0040 line 行缓冲
#define _IONBF 0x0004 No 无缓冲

 

  • 用法示例
    1    char str[4096] = {0};
    2     setvbuf(stdout,str, _IOFBF, 4096);
    3     fprintf(stdout, "hello \n");
    4     fflush(stdout);
    5     system("pause");

     

  • 设置文件缓冲区实时写入
    1 void main()
    2 {
    3 
    4     FILE *pf = fopen("C:\\2.txt", "w");
    5     setvbuf(pf, NULL, _IONBF, 0);
    6     fputs("1234567890", pf);
    7 
    8     system("pause");
    9 }

     

posted @ 2018-02-22 09:15  喵小喵~  阅读(239)  评论(0编辑  收藏  举报