From: cbalciza AT mail DOT cccis DOT ro To: dj AT delorie DOT com, eliz AT is DOT elta DOT co DOT il, csrabak AT dce03 DOT ipt DOT br, eldredge AT ap DOT net, djgpp AT delorie DOT com (djgpp mailing list) Subject: can't write to existing file (C++ I/O problem) Date: Mon, 15 Sep 97 04:21:15 GMT Message-ID: Precedence: bulk Problem: - (existing) file content discarded when trying to (C++) read and write. Purpose: - updating records into an existing database Goals so far: - works if using C style fopen with 'r+' - fails if using C++ style ifstream f("test.txt", ios::nocreate | ios::in | ios::out | ios::binary); IDE: -RHIDE & DJGPP 2.01 using the following switches: gcc -g -c test.cc -o test.o gcc -o test.exe test.o -liostr Input file test.txt containing 42 bytes as follows: abcdefghijklmnopqrst 12345678901234567890 Expected output: jihgfedcbaklmnopqrst 12345678901234567890 Actual output: GARBAGE Program: // test program #include #include #include int main(void) { ifstream f("test.txt", ios::nocreate | 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