What is the best way to determine the size of a file? I've opened it for read access using fopen(), and would like to know the size of the file before I proceed further. I checked MSDN and found a list of stream i/o functions, but didn't see anything for this. I suppose that I could do something like this
Code:
cout<<"Reading data from input file..."<<endl;
int len=0;
char temp[1];
while(fread(temp, 1, 1, input))
len++;
cout<<len<<endl;
But that isn't working. I also tried
Code:
int len=0;
char temp[1];
len=fread(temp, 1, 100000000, input);
cout<<len<<endl;
But for some reason, that always gave me 0, even though fread(), according to MSDN, "returns the number of full items actually read, which may be less than countif an error occurs or if the end of the file is encountered before reaching count.
So, how do you determine the size of a file in bytes? Thanks.