[英]Is there anyway redirecting (cin) input from txt file in console twice, for C++?
It is rather convenient to redirect input stream from different txt files in CMD console, since I don't need to write a file name and open it in my code. 在CMD控制台中从不同的txt文件重定向输入流非常方便,因为我不需要编写文件名并在代码中打开它。 Like typing
code.exe < input.txt
in windows OS. 就像在Windows操作系统中键入
code.exe < input.txt
一样。
However, if I want to redirect two file like input1.txt and input2.txt to two input streams( cin>>
) located in two positions of my code. 但是,如果我想将两个文件(如input1.txt和input2.txt)重定向到位于我的代码两个位置的两个输入流(
cin>>
)。 How should I deal with it? 我应该如何处理? I just know how to redirect once rather than multiple times.
我只知道如何重定向一次,而不是多次。 Any help would be appreciated.
任何帮助,将不胜感激。
Getting the two inputs in is the simple problem: TYPE file1.txt file2.txt > code.exe
. 输入两个输入是一个简单的问题:
TYPE file1.txt file2.txt > code.exe
。 But how would your first std::cin
statement know which line is the last line of file1.txt
? 但是,您的第一个
std::cin
语句如何知道file1.txt
的最后一行呢?
The normal solution is to use code.exe file1.txt file2.txt
, and read both files using their own std::ifstream
. 正常的解决方案是使用
code.exe file1.txt file2.txt
,并使用它们自己的std::ifstream
读取这两个文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.