Den 8. feb. 2007 kl. 15.21 skrev Paul Herring:
>
> It is very rare that you should be using EOF functions directly in a C
> or C++ program - you should instead be checking for an error in the
> reading of data from a file. Then, and only then, should you be using
> the EOF functions to determine if indeed it is the end of the file (or
> someone's removed the floppy disc from the drive etc.)

Why is that? I've always used it when reading from a text file.  
Checking for other errors usually isn't necessary.

> Show your code!

It's very simple. Essentially it goes like this:

ifstream(filename) ui;
while(!ui.eof())
{
    if(baner==NULL) baner = b = new bane;
    else { b->neste = new bane; b=b->neste; }
    ui >> b->fork >> b->type >>....>> b->ist;
}
ui.close();

It reads all the actual lines correctly, but then goes on to read  
endless null lines. The file does contain linefeeds, but as far as I  
have understood, these are skipped when the skipws flag is set, which  
(as far as I have understood) it is by default.

I am trying to convert from a half-automated system using MS Excel by  
converting the Excel table to text and reading the text file into the  
C++ program. Not quite decided on how to store the data in the C++  
system yet. It consists of several tables, corresponding to several  
classes in C++.

LEF

Reply via email to