我想通过这种方式将文件作为参数传递:
a.exe < testfile
如何在我的C代码中获得testfile
?
编辑
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char b[50];
gets(b);
puts(b);
//stuff
return 0;
}
我对此进行编译,并且当我通过这样的CL运行它时
a.exe < testfile
我明白了
`
那是为什么?我在拟议的解决方案中阅读了有关stdin的信息,但现在我被困在这里。
答案 0 :(得分:1)
重定向< testfile
将标准输入流替换为文件testfile
。
读取输入内容就像使用stdin从键盘读取数据一样。
答案 1 :(得分:1)
将其作为stdin
来获取,因为这就是在shell重定向(以及可执行文件中的libc初始化)之后的结果。