Read file as input from the command line
c, c++
Solution
When a program is invoked like this `./a.out < file`, the content of the file will be available on the standard input: `stdin`.
That means that you can read this content by reading the standard input.
For example:
- `read(0, buffer, LEN)` would read the from your file.
- `getchar()` would return a char from your file.
Problem
I am trying to read a file from the command line passed as input. No not the filename. I'm not expecting the user to input a filename on the command-line, so that I could open it like this : `fopen(argv[1], "r");`. I am expecting a file like this : `myprogram < file_as_input`. So whatever should go into argv is the contents of the file. How do I do this in C/C++ ?