Opening a file in binary

This is a discussion on Opening a file in binary within the C++ Programming forums, part of the General Programming Boards category; I am writing a function to open a binary file. It has two arguments, the first is a struct which ...

Opening a file in binary

I am writing a function to open a binary file. It has two arguments, the first is a struct which the files info will be read and stored to, the second is a C style string containing the name of the file to open. I was given the following code by my instructor to start off with:

Just to let you know, the function is supposed to return an int; if the file opens, it returns a positive value. If the file does not open correctly, the function returns a negative value. I have not written this part of the code yet, and did not think it relative to my question, but if it is, let me know. Anyway, my question is what do the arguments of infile.read() mean, and how does the read file use them. Thanks for reading. Any help would be appreciative.

Where *buf is the target variable you want to hold the value read. Much like cin>>x. streamsize is a typedef for unsigned long int (i think) and num is the number of bytes to be read.
Im not sure why your instructer input 0 as the variable to be read.