delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/12/08/14:31:44

Subject: C++ File Handling
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Thu, 8 Dec 1994 12:18:17 +0000 (GMT)
From: "B.S.Runnacles" <B DOT S DOT Runnacles AT soton DOT ac DOT uk>

Dear all

I am having problems in using the file handling libraries under GPP.
I am trying to read a text file created using  G++ with the streamed
I/O routines.  The ifstream object opens the file OK, but returns EOF
for every file access afterwards.  I am trying to extract newline
delimited strings and floats from the file.  The code goes something
like this....

ifstream file;
file.open(filename, ios::nocreate);
if (!file.is_open()) cout << "Can't open file \n" // This works fine
float temp; 
char buffer[100] = {0};
file >> buffer;

whereupon the file access fails, and file.eof() is set.  I prototyped
this using (dare I say it) Microsoft Visual C++ 1.00 and it works
fine.  Is there a known problem with streamed file input.  A revised
version using standard C style file pointers works nicely.

Any ideas?

Ben Runnacles
Vision, Speech and Signal Processing Group,
University Of Southampton, U.K.

- Raw text -


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