提问人:Milk_Cool 提问时间:10/11/2023 更新时间:10/11/2023 访问量:77
无法在 C 语言中关闭线路缓冲
Cannot turn off line buffering in C
问:
因此,我正在处理一个大项目,它需要禁用 stdin 和 stdout 缓冲区,以便立即处理输入和输出。但是,当我尝试使用 or 时,它就不起作用了。这是我的代码:setbuf
setvbuf
#include <stdio.h>
#include <stdbool.h>
int main() {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
while(true) {
char a = getchar();
printf("%c", a);
}
return 0;
}
我正在使用 linux,但是我无法在 Windows 计算机上对其进行测试,因此我无法确认这是否是 linux 问题。
这是它不起作用的视频:https://youtu.be/EWs5H_6h9DQ
答:
0赞
Milk_Cool
10/11/2023
#1
因此,解决方案是使用 .我从这里拿走了代码,它运行良好!termios
评论
0赞
arfneto
10/12/2023
从 Unix 开始,您有一个默认的熟模式来处理流,以及一个可选的原始模式。在 Windows 下,同样的东西称为 LINE INPUT 模式。在 Linux 下,使用 to 设置 ,在 Windows 下,使用控制台功能。它不同但相似。ioctl
termios
struct
评论
ioctl
termios
struct