cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/13/20:31:28

From: "Arnold K. Poon" <akpoon AT us DOT oracle DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: fin problem with djgpp
Date: Sun, 13 Sep 1998 16:59:17 -0700
Organization: Oracle Corporation. Redwood Shores, CA
Lines: 47
Message-ID: <35FC5C55.E6A2570D@us.oracle.com>
Reply-To: "Winrider AT ix DOT netcom DOT com;akpoon"@us.oracle.com
NNTP-Posting-Host: akpoon-pc4.us.oracle.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

    i wrote a small program to read a file and store the file contents
into several variables
    The DJGPP compiled version did not "understand" EOF and execute the
"while" statement once more before quiting.

 #include <iostream.h>
#include <fstream.h>

int main(void)
{
 ifstream fin("test.txt");

 char x[20],y[20];
 int z;

 while (!fin.eof())             <<< somehow EOF is not read correctly
 {
  fin >> x >> y >> z;
  cout << "x=" << x << " y=" << y << " z=" << z << endl;
 }
 fin.close();

 return 0;
}


the acutal file contents

Atlanta Boston 0400
Atlanta Chicago 0135
Atlanta Detroit 0320
Boston Chicago 0345
Boston Detroit 0120
Chicago Detroit 0200


    The program is suppose to read each line and print that out.
However, when I use DJGPP to compile, I got an extra line of output. The
EOF variable was NOT set to ZERO after reading file, therefore the while
loop enters 1 more time and print out some bogus output.

    However, if i compile with MSVC++5.0 (default workspace), I did not
get this problem.

    Am I using EOF correctly? or is there something different between
MSVC and DJGPP compiler?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019