By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

Last record added twice when reading ifstream

P: n/a
Ok, so logically this code seems to make sense but for some reason it
reads the last record twice before hitting eof. Is ifstream.eof()
implementation dependent?

void LoadFile(ifstream &File, List &List)
{
User lUser;
while(!File.eof())
{
File >lUser;
List.insert(lUser,List.nodeCount());
}
}

Mar 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 3/23/2007 1:42 PM, Kenneth wrote:
Ok, so logically this code seems to make sense but for some reason it
reads the last record twice before hitting eof. Is ifstream.eof()
implementation dependent?

void LoadFile(ifstream &File, List &List)
{
User lUser;
while(!File.eof())
{
File >lUser;
List.insert(lUser,List.nodeCount());
}
}
Look Here:

http://www.gnomesane.net/code/doc/noteof/

S.
--
Stefan Naewe
stefan_DOT_naewe_AT_atlas_DOT_de
Mar 23 '07 #2

P: n/a
Kenneth wrote:
Ok, so logically this code seems to make sense but for some reason it
reads the last record twice before hitting eof. Is ifstream.eof()
implementation dependent?

void LoadFile(ifstream &File, List &List)
{
User lUser;
while(!File.eof())
{
File >lUser;
List.insert(lUser,List.nodeCount());
}
}
This is an FAQ (I'd even say one of the most F AQs).
It's answered in the C++ FAQ lite at http://www.parashift.com/c++-faq-lite .

Mar 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.