Connecting Tech Pros Worldwide Help | Site Map

Last record added twice when reading ifstream

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 23rd, 2007, 12:45 PM
Kenneth
Guest
 
Posts: n/a
Default Last record added twice when reading ifstream

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());
}
}


  #2  
Old March 23rd, 2007, 01:05 PM
Stefan Naewe
Guest
 
Posts: n/a
Default Re: Last record added twice when reading ifstream

On 3/23/2007 1:42 PM, Kenneth wrote:
Quote:
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
  #3  
Old March 23rd, 2007, 01:45 PM
Rolf Magnus
Guest
 
Posts: n/a
Default Re: Last record added twice when reading ifstream

Kenneth wrote:
Quote:
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 .

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.