Mail Archives: djgpp/1997/02/10/19:09:33
A friend of mine found a bug in `fstream' class of the `iostream'
library. The bug makes impossible opening single file for both
reading and writing. It is present in both 2.00 and 2.01
versions.
The example program is included below. It produces the following
results:
on Sparc with Solaris 2.4 and gcc 2.7.2:
[klm/k-m] (correct)
on PC with DOS and Borland C++ 3.1:
[mlk/m-k] (also correct, I think :-)
on PC with DOS and DJGPP 2.xx:
[ / ] (not spaces, but (char)(255), also data file corrupted)
Any suggestions?
============================== program begin
#include <fstream.h>
#define FILENAME "fstr.dat"
void fileCreate (void) {
ofstream f(FILENAME);
for (char c = 'a'; c != 'z'; c++) f << c;
} // fileCreate
void fileReadWrite (void) {
fstream f(FILENAME,ios::in|ios::out);
f.seekg(10);
cout << '[' << (char)(f.get()) << (char)(f.get()) << (char)(f.get());
f.seekp(11);
f.put('-');
f.seekg(10);
cout << '/' << (char)(f.get()) << (char)(f.get()) << (char)(f.get());
cout << ']' << endl;
} // fileReadWrite
int main (void) {
fileCreate();
fileReadWrite();
return 0;
} // main
============================== program end
--
Jerzy Witkowski <Jerzy DOT Witkowski AT ii DOT uni DOT wroc DOT pl> o o
University of Wroclaw, Institute of Computer Science /| | |/|
Przesmyckiego 20, PL-51151 Wroclaw |/| | |
room: 11, phone: 0048 71 3247360 /| |/^\| |
phone/fax office secretary: 0048 71 3251271 <__|
- Raw text -