This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

tellg modifying the state of an input file stream


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]