开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
C
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
stdio.h
string.h
问题(Question):
实际测试和原本有出入
喂入的资料(Input):
预期的正确结果(Expected Output):
http://www.tutorialspoint.com/c_standard_library/c_function_setvbuf.htm
如这篇
错误结果(Wrong Output):
Going to set full buffering on
This is tutorialspoint.com
This output will g into buff
请按任意键继续 . . .
少了两行
程式码(Code):(请善用置底文网页, 记得排版)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{
char buff[1024];
memset(buff, '\0', sizeof (buff));
fprintf (stdout, "Going to set full buffering on\n");
setvbuf (stdout, buff, _IOFBF, 1024);
fprintf (stdout, "This is tutorialspoint.com\n");
fprintf (stdout, "This output will g into buff\n");
fflush (stdout);
fprintf (stdout, "and this will appear when programm\n");
fprintf (stdout, "will come after sleeping 5 seconds\n");
sleep (5000);
system("PAUSE");
return 0;
}
补充说明(Supplement):
参阅这网站:http://blog.xuite.net/mb1016.flying/linux/28543400-fflush(stdout)
多少理解fflush的意思,可是我自己测试跟实际有点出入。
为什么我fflush 之后就被截掉了? 我印象中他展示是没有被截掉。
还有设定 setvbuf有何功用?