Archived

This topic is now archived and is closed to further replies.

End of File?

This topic is 4944 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've got this in my code
std::string sFile;
char ch; // Create Char to Load Data into String

while (!infile.eof())  // Load all the file into a string

{
   infile.get(ch);
   sFile += ch; //Add all data to the string

} 
but for some reason, it always adds another of whatever was the last character does anyone know why it does this? because as soon as the end of the file hits...its suppose to not execute the code right?? so whats going on? <SPAN CLASS=editedby>[edited by - kag1 on May 29, 2004 1:13:31 PM]</SPAN>[/source] [edited by - kag1 on May 29, 2004 1:14:23 PM]

Share this post


Link to post
Share on other sites

std::string sFile;
char ch; // Create Char to Load Data into String

while (infile.get(ch)) // Load all the file into a string

{
sFile += ch; //Add all data to the string

}

I *think* get works the same way as the << operator and it''ll return false if its an EOF/other error

Share this post


Link to post
Share on other sites