I copied this code out from one of my c++ books from the chapter concerning file I/O, and, specifically, binary operations on a file. I found this section not to be very well explained and I'm not sure what this code is meant to do. I'm guessing you need to feed main() a text file from the same directory you have your code saved in and the code reads the file as binary and outputs the result as characters. But, as it is main() does not take any file as a parameter and when I run it it just outputs: Usage: PR <filename>
So what is this code supposed to do? Thanks in advance.
That code expects you to run the program from the command line prompt, and expects the filename to be supplied as a parameter. Say your program is called test1.exe and the input file is called myfile.txt. You would type on the command line: test1.exe myfile.txt
If you run the program from within an IDE, there should be a menu option where you can type in the parameter value (that is, the name of the file). Usually to be sure the file will be found, you would specify the full path to the file, for example "C:\myfiles\myfile.txt"
Alternatively, you could type the full file name in the program itself, like this, (note each '\' has to be typed as a double '\\'.
Many thanks fr your reply, so far I have tried entering the command line prompt, and entering the parameter value into the IDE, it worked and I was able to read form the file, but a short text file saying:
You need to save the file as plain text. It looks like you have a RTF document there which includes all sorts of extra formatting details (font name, font size etc.).