This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
tellg modifying the state of an input file stream
- From: Ivan Kolev <ikolev at abac dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Sat, 20 May 2006 17:33:17 +0300
- Subject: tellg modifying the state of an input file stream
- References: <1148134788.31547.ezmlm@gcc.gnu.org>
Hi,
I have an example which looks like a bug. I use gcc 3.4.5 for MinGW on Windows. Here is the code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream ofs( "streamtest.txt" );
ofs << "Test" << endl; // <1>
ofs.close();
ifstream ifs( "streamtest.txt" );
char c;
ifs.get(c);
while ( ! ifs.fail() ) {
unsigned p = ifs.tellg(); // <2>
cout << "c = " << c << ", pos: " << p << endl;
ifs.get(c);
}
ifs.close();
}
This program prints
c = T, pos: 2
c = s, pos: 4
c =
, pos: 6
If either endl is not written to the file at line <1> or tellg() is not called at line <2> the output is as expected, i.e.:
c = T
c = e
c = s
c = t
Regards,
Ivan