Computer Science Canada

Check to see if file is empty

Author:  cyberguy [ Mon Jan 04, 2010 7:38 pm ]
Post subject:  Check to see if file is empty

Is there any if statement to check if a file is empty?

Author:  DemonWasp [ Mon Jan 04, 2010 7:57 pm ]
Post subject:  RE:Check to see if file is empty

You can probably just check the file's size or length against 0. If it's 0, the file is empty, otherwise not. I don't know how you'd find the length of a file in C++ offhand though.

Author:  TheGuardian001 [ Mon Jan 04, 2010 8:00 pm ]
Post subject:  Re: Check to see if file is empty

I believe you can do this using istream::peek(), which returns the value of the next character in a file, but leaves it as the next character to be read.

open a file, peek(), and if it returns EOF, your file is empty.


: