When using redirection on the command line, argv does not contain redirection.
The specified file just becomes your stdin / cin.
Therefore, there is no need to open it with fopen , just read from standard input.
Example:
using namespace std; int main() { vector <string> v; copy(istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(v)); for(auto x:v) cout<<x<<" "; return 0; }
test <input.txt
Exit
The contents of the input.txt section, separated by a space
source share