delorie.com/archives/browse.cgi | search |
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 <Pavel DOT Kudrna AT mff DOT cuni DOT cz> |
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 |
X-IsSubscribed: | yes |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
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 <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/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |