I tried to run the code (saved as 1.cpp, see at the end) in my linux:
I input in the terminal: g++ 1.cpp
Then ./a.out hello.txt
I thought it would output the file of hello.txt. However, the result is that it indeed outputs the file. But before the content of file, there are garbage characters. I just don't know why. Any kind of help would be appreciated!
argv[0] is the name of the executable. Your loop starts at i == 0, you open the executable on line 8, and you read it as if it was a text file on line 11.