This is the mail archive of the
cygwin
mailing list for the Cygwin project.
fstream - problem with reading/writing to file
- From: Pavel Kudrna <Pavel dot Kudrna at mff dot cuni dot cz>
- To: cygwin at cygwin dot com
- Date: Thu, 19 Feb 2009 20:10:33 +0100
- Subject: fstream - problem with reading/writing to file
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/