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/