[英]Interactive scanf using pipe
I try to read a value from console in unix using pipe 我尝试使用管道从UNIX中的控制台读取值
exmpl.cpp: exmpl.cpp:
#include <stdio.h>
int main()
{
int d;
scanf("%d",&d);
printf("d=%d",d);
return 0;
]
So, when i use 所以,当我使用
./a.out < tmp
I get the number from tmp immidiately, but i want to get number from console 我立即从tmp取得号码,但我想从控制台取得号码
Also, I tried to use 另外,我尝试使用
fscanf(stdin, "%d",&d);
but it didn't help 但这没有帮助
You can't really do that. 你真的不能那样做。 With
<
you've changed the stdin of the program, therefore you can't use stdin for user interaction anymore. 使用
<
您已经更改了程序的标准输入,因此您不能再使用标准输入进行用户交互了。
Consider using tmp
file as an argument. 考虑使用
tmp
文件作为参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.