In C, all you need to do is read the file descriptor 0:
read(0, …, …);
In C++, you can do this by using std::cin
:
#include <iostream>
int main() {
std::cin >> /* a variable you want to direct the input to */
return 0;
}
That's standard C++ that is fully compatible with boost. For the way to use it, I leave it to you to read more on the manual and the plethora of examples you can find online.
for opening a file or reading from stdin you can do something in the following fashion:
shared_ptr<istream> input;
if (filename == "-" || filename == "")
input.reset(&cin, [](...){});
else
input.reset(new ifstream(filename.c_str()));
// ...
(answer copied from https://stackoverflow.com/a/2159469/1290438)
Basically, if you don't give a filename parameter, you consider data comes from stdin. That's the way cat works.