Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Check to see if file is empty
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cyberguy




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: 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.
TheGuardian001




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: