X-Recipient: archive-cygwin@delorie.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 <Pavel.Kudrna@mff.cuni.cz>
User-Agent: Thunderbird 2.0.0.9 (Windows/20071031)
MIME-Version: 1.0
To: cygwin@cygwin.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@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.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 <iostream>
#include <fstream>

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/

