Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将C程序设置为行缓冲区赢得';行不通_C_Stdout_Buffering - Fatal编程技术网

将C程序设置为行缓冲区赢得';行不通

将C程序设置为行缓冲区赢得';行不通,c,stdout,buffering,C,Stdout,Buffering,我试图强制我的C程序使用行缓冲区(stdout将被java程序捕获),但它似乎总是完全缓冲。以下是一些示例代码: #include <stdio.h> #include <stdlib.h> int main(){ char c; setvbuf(stdout, NULL, _IOLBF, BUFSIZ); printf("Hello world\n"); c = getchar(); printf("got char: %c\n

我试图强制我的C程序使用行缓冲区(stdout将被java程序捕获),但它似乎总是完全缓冲。以下是一些示例代码:

#include <stdio.h>
#include <stdlib.h>

int main(){
    char c;
    setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
    printf("Hello world\n");
    c = getchar();
    printf("got char: %c\n", c);
}
#包括
#包括
int main(){
字符c;
setvbuf(标准输出,空,_IOLBF,BUFSIZ);
printf(“Hello world\n”);
c=getchar();
printf(“获取字符:%c\n”,c);
}
如果我指定了_IOLBF或_IOFBF,那么在输入字符之前我不会看到输出。只有使用_IONBF,才能在getchar()之前看到输出。既然“Hello World\n”包含“\n”,那么IOLBF不应该这样做吗

我使用Visual C++ 2005。< /P> 感谢

根据:

_IOLBF: 对于某些系统,这提供了行缓冲。但是,对于Win32,其行为与_IOFBF-完全缓冲相同


您检查了
setvbuf
的返回值了吗?啊,可以了。谢谢