c++ - sebuf设置缓冲区大小,但并不是按照设定的大小刷新
怪我咯
怪我咯 2017-04-17 11:08:49
0
2
549
 #define BUFSIZE 3

int main(){

char c;
static char buf[BUFSIZE];
setbuf(stdout, buf);
while ((c = getchar()) != EOF){
    putchar(c);
   }
}

但是结果并不是像我想象的按照输入三个字符会自动刷新?请问这是什么问题?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
左手右手慢动作

Read the document clearly for yourself:

void setbuf(FILE *stream, char *buf);
...
The setbuf() function is exactly equivalent to the call

   setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);

To specify the size, use setbuffer.

PHPzhong

$ man setbuf

The setbuf() function is exactly equivalent to the call

setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);

Note the BUFSIZ at the end.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template