Xref: news2.mv.net comp.os.msdos.djgpp:3793 From: Dieter Demerre Newsgroups: comp.os.msdos.djgpp Subject: bug in fstream ? (V2) for in-out files ? Date: Mon, 13 May 1996 16:27:13 +0200 Organization: K.U.Leuven Lines: 58 Message-ID: <319746C1.41C67EA6@cs.kuleuven.ac.be> NNTP-Posting-Host: pluto.cs.kuleuven.ac.be Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit CC: Dieter DOT Demerre AT cs DOT kuleuven DOT ac DOT be To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp A couple of months ago I installed DJGPP for I wanted to compile my program with it. Just last weekend I found that not all objects behave like they do in BC3.1. I hereby include my testprogram (partly) that tries to read from a file but also write to it. I find that whenever I open the file to write in it, the file is renewed, while this is NOT done in Borland C++ nor in the C++ compiler we have here on the VAX- and ALPHA-machines. Did I do anything wrong ? // filename: filetest.cpp // date : 1996-05-13 // descript: Will create a file if it does not exist yet, // will write at the end, read at the beginning, // write at the end, write at the beginning // write at the end. #include #include int main() { fstream a_stream; char st[200]; a_stream.open("test.fil",ios::in|ios::out|ios::nocreate|ios::ate); cout << "test.fil in-out-opened" << endl; if (!a_stream.good()) { a_stream.open("test.fil",ios::out); a_stream.close(); a_stream.open("test.fil",ios::in|ios::out|ios::ate); }; if (a_stream.good()) { a_stream << "Test this file." << endl; a_stream.seekg(0,ios::beg); a_stream >> st; a_stream.seekp(0,ios::end); a_stream << "this file has an end." << endl; a_stream.seekg(0,ios::beg); a_stream << "begin" << endl; a_stream.seekp(0,ios::end); a_stream << "end test" << endl; a_stream << "beginning had \"" << st << "\"" << endl; a_stream.close(); } else { cout << "a_stream cannot be created" << endl; }; return 0; }; Greetings from = Groetjes vanwege -------------------------------------------- Dieter Demerre Email : Dieter DOT Demerre AT cs DOT kuleuven DOT ac DOT be http : www.cs.kuleuven.ac.be/~demerre --------------------------------------------