Like This Site? 
 
RSS Feed Follow Us 

on Twitter! Be Our Fan!

C++ : EOF(End of The File) and reading text files

Share this post!
 Vote this!

The Problem
This article is intended to address the plethora of posts to Dream.In.Code's C and C++ forum where a poster has doomed their program to weird behaviour under the innocent assumption that using "EOF" is a sure way to know that there's no more data to read from their file

  • What?? E.O.F. stands for 'End Of File', surely that means there's no more data?
Yes, kind of. Sorry if this hurts your head, but 'end of file' in C++ does not mean the same thing as 'no more data'.


Take a look at this short program which works with a file storing 5 names, and more importantly, what happens when 'eof' is used as the breaking condition for reading data into a vector.  more..

0 comments:

Post a Comment