Mail Archives: djgpp/1996/05/13/13:38:22
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 <iostream.h>
#include <fstream.h>
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
--------------------------------------------
- Raw text -