cout << argv[1];
is equivalent to:
char* arg = argv[1];
cout << arg;
It just prints the value of the first argument in the program
In your case, you did not provide an argument to the program.
When you use
./program < input.txt
the content input.extbecomes stdinyour program. You can handle this using:
int c;
while ( (c = fgetc(stdin)) != EOF )
{
fputc(c, stdout);
}
If you want to stay with C ++ streams, you can use:
int c;
while ( (c = cin.get()) != EOF )
{
cout.put(c);
}
source
share