Redirect cin (c++) to multiple files in cmd

I have been searching it, but I cant manage to found the way. Basically I have two files: "hello.txt" and "bye.txt":

hello.txt:

1 2 3 8 8

bye.txt:

9 9 8 1 2

I know how to redirect cin to hello.txt using:

a.exe < hello.txt

So cin will recieve "1 2 3 8 8". But how can I make it to recieve info from both files "1 2 3 8 8 9 9 8 1 2". I have already tried to duplacate the <:

a.exe < hello.txt < bye.txt

But it didnt work, I also tried this:

a.exe < hello.txt <& bye.txt

But from what I read it wont work (It didnt). Any ideas? Thanks

Answers


It is not relevant to C++. Either you could change the code and read from many files provided as command line or you redirect first all files in one and read that one then:

type hello.txt > tmp.txt
type bye.txt >> tmp.txt
e.exe < tmp.txt

If available on your system, you can use cat for this:

cat file1 file2 file3 | a.exe

See it live.


Since you've asked this on Stack Overflow, and not Super User, here is a poor man's cat implementation, in C++, with a lot of room for improvement.

#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();
    }
}

If you compile this to a program called cat, you can then use it like this:

cat hello.txt bye.txt | a.exe

Although I'm sure there are proper full-featured implementations of cat for Windows out there if you look.

My personal preference on Windows would be to switch to Powershell and use Get-Content.

Get-Content hello.txt, bye.txt | a.exe

Need Your Help

PHP retrieving data, but returns Resrouce id#4

php sql-server sqlsrv

I try to use sqlsrv_query to get data from microsoft database. this is my code:

.NET / COM events interoperability

c# .net com interop com-interop

I have an interop assembly generated by TlbImp.exe, the generated classes are heavily evented and the performance is very important.