473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

Mar 23 '07 #1
2 3571
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Wen | last post by:
Hallo, Can someone tell me why my while doenst read the second, third.... record? (This's a part of my code.) I've looked for it in the books and on internet, but juist don't see the probleem....
12
by: francisds | last post by:
Hi, Can you guys see if there's a solution to this problem? I have a database from which I have to read each record and process that record. New records are being added all the time, so I...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
12
by: Curten | last post by:
Hi, I'm using ifstream to read data from a txt-file but the last line is always read twice. How Come? The condition for the loop in which the file is read is while(!infile.eof()) so this...
1
by: empaleador | last post by:
Hi I m reading a file that ends with a blank line and when i do the output it repeats the line before the blank 2 times. I am using ifstream infile; infile.open...
11
by: Timofmars | last post by:
I'm try to Unload DB2 data from a table into a record sequential file on NT. I can an unload on Mainframe, but it doesn't seem to be an option in NT. In NT, all I can do is export/import. I can...
4
by: Rasputin | last post by:
Hello, The topic of this question is somewhat related to my previous question, but I wasn't sure if it diserved its own thread. In case of doubt... I double threated. If it's not OK let me...
7
by: ramana | last post by:
I'm wondering if someone could point me to the flaw in the following code that uses the while(!FP.eof()) condition to read the input data. This condition is reading the last data point of the file...
3
by: rutabuga | last post by:
after opening the text file the the prog is soposed to read each record into certain variables and then display the variable name to the screen the problem i am geting is that the last record in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.