From: cbalciza AT mail DOT cccis DOT ro To: djgpp AT delorie DOT com (djgpp mailing list) Subject: file I/O (R/W) problem Date: Mon, 08 Sep 97 10:48:09 GMT Message-ID: Precedence: bulk how can I open a file for both reading and writing without erasing the previous file content ? here's a little test program taken from an ANSI C++ manual and applied to a file (test) containing: This is a test program; it should modify it to: a si sihTtest program; yet I only get: TTTTT HHHHH please reply // test program #include #include #include int main(void) { fstream f("test", ios::in | ios::out | ios::binary); if (!f) { cout << "cannot open file" << endl; return 1; } long e,i,j; char c1,c2; e=10; for (i = 0, j = e ; i < j ; i++ , j--) { f.seekg(i,ios::beg); f.get(c1); f.seekg(j,ios::beg); f.get(c2); f.seekp(i,ios::beg); f.put(c2); f.seekp(j,ios::beg); f.put(c1); } f.close(); return 0; }