我一直在搜索它,但是我无法找到方法。基本上我有两个文件:" hello.txt"one_answers" bye.txt":
hello.txt:
1 2 3 8 8
bye.txt:
9 9 8 1 2
我知道如何将cin
重定向到hello.txt
:
a.exe < hello.txt
所以CIN将收到"1 2 3 8 8"
。但是,我该如何从两个文件"1 2 3 8 8 9 9 8 1 2"
中收到信息。我已经尝试将<
重复出现:
a.exe < hello.txt < bye.txt
但是它没有起作用,我也尝试了以下方法:
a.exe < hello.txt <& bye.txt
,但我从我阅读的内容中无法使用(没有)。有任何想法吗?谢谢
它与C 无关。您可以更改代码并从提供的许多文件中读取命令行,或者首先重定向所有文件,然后读取该文件:
:type hello.txt > tmp.txt
type bye.txt >> tmp.txt
e.exe < tmp.txt
如果在系统上可用,则可以使用cat
:
cat file1 file2 file3 | a.exe
看到它活的。
由于您已经在堆栈溢出上问了这个问题,而不是超级用户,这是一个可怜的男人的猫实施,在C 中,有很大的改进空间。
#include <iostream>
#include <fstream>
int main(int argc, char** argv)
{
for (int i = 1; i < argc; ++i)
{
std::ifstream fin(argv[i]);
std::cout << fin.rdbuf();
}
}
如果将其编译为称为CAT的程序,则可以这样使用:
cat hello.txt bye.txt | a.exe
尽管我敢肯定,如果您看到的话,cat有适当的全功能实现。
我对窗口的个人喜好是切换到powershell并使用Get-Content
。
Get-Content hello.txt, bye.txt | a.exe