tellg()

hi guys,
i am doing program of file handling in which im using tellg() function(in the form fstream_name.tellg().but because of tellg its producing adverse effects.Actually i trying to recording position of get pointer by tellg() before reading line and again using seekg(value of tellg) to go to that line but its affecting program output ,im not getting wht to do as if i comment out line containing tellg() program works properly.
here is program(run it without commenting tellg()code and after commenting it)
why output is different????
##############################################################
#include<fstream>
#include <cstdlib>
#include <iostream>
#include<string>
using namespace std;
int main()
{
fstream f1;
f1.open("file.txt");
char str[30];
while(f1)
{
int t=f1.tellg();
f1.getline(str,sizeof(str));
cout<<str<<"\n";
}
cin.get();
}
########################################################
input text file
20100819 9:00:01 AM 103.95
20100819 9:00:03 AM 103
20100819 9:00:03 AM 103
20100819 9:00:03 AM 103
20100819 9:00:05 AM 103.05
20100819 9:00:05 AM 105.9
20100819 9:00:06 AM 105.7
20100819 9:00:06 AM 105.15
20100819 9:00:06 AM 105.65
20100819 9:00:06 AM 102
20100819 9:00:06 AM 102
20100819 9:00:06 AM 102
20100819 9:00:06 AM 102
20100819 9:00:07 AM 102
20100819 9:00:07 AM 102
20100819 9:00:07 AM 102
20100819 9:00:07 AM 102
20100819 9:00:07 AM 102
20100819 9:00:08 AM 103.95
20100819 9:00:08 AM 104
20100819 9:00:10 AM 103.2
20100819 9:00:11 AM 103.2
20100819 9:00:11 AM 103.25
20100819 9:00:11 AM 103.2
20100819 9:00:12 AM 103.9
20100819 9:00:12 AM 103.95
20100819 9:00:12 AM 103.15
20100819 9:00:12 AM 103.1
20100819 9:00:12 AM 103.9
20100819 9:00:13 AM 103.2

When I compile and run your program, I get the same output whether or not the tellg() line is commented out. I'm using gcc 4.1.2.
The tellg() and seekg() methods of the STL iostreams are broken unless you open the stream with ios::binary. Alas.
Topic archived. No new replies allowed.