X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=3.9 required=5.0 tests=BARRACUDA_BRBL,BAYES_50,J_CHICKENPOX_45,RCVD_IN_BL_SPAMCOP_NET X-Spam-Check-By: sourceware.org Message-ID: <499DAEA9.90309@mff.cuni.cz> Date: Thu, 19 Feb 2009 20:10:33 +0100 From: Pavel Kudrna User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: fstream - problem with reading/writing to file Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hi, I have found problem with read and write to file using fstream. The following example opens existing file for read+write, separately writes "Hello" and " world!" and in between it tries to read one character from the file. The problem is that without call to seekg() or tellg() the read fails and without seekp() or tellp() the second write of " world!" to the file fails too. The same program works on linux with gcc 3.2.2. Pavel Kudrna $ cat rw.cpp #include #include using namespace std; int main() { fstream f( "file" ); f << "Hello"; // f.seekg( 0, fstream::cur ); // cout << "Get position: " << f.tellg() << endl; char c; f >> c; cout << "Read character: " << c << endl; // f.seekp( 0, fstream::cur ); // cout << "Put position: " << f.tellp() << endl; f << " world!"; return 0; } $ g++ -g -o rw rw.cpp $ echo 0123456789 >file; ./rw; cat file Read character: Hello56789 $ gcc -dumpversion 3.4.4 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/