TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JAMIE KOWINSKY
from: THOMAS MAEDER
date: 1997-12-01 21:09:00
subject: Reading to the end of fil

JK> What is the prefered loop for reading to the end of a file?
JK> while (!filestream.eof())
JK> or
JK> while (!filestream.fail())
eof() tells you if the stream has reached its end. fail() tells you if
the  last  (reading)  operation  has  failed.  If  you  have access to
comp.lang.c++.moderated (or was  it  comp.std.c++?  I  don't  recall),
there  was a discussion ("the good(), the bad() and the fail()") about
these memember functions.
I personally would use the simplest possibility:
while (filestream >> myData)
    // work with myData
Thomas
---
 þ MM 1.0 #0113 þ The penalty for bigamy is two mothers-in-law.
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.