read.cpp
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
int id;
char name[50];
ifstream myfile("savingaccount.txt"); //open the file
myfile >> id;
cout << myfile.tellg(); //return 16? but not 7 or 8
cout << id ;
return 0;
}
savingaccount.txt
1800567 Ho Rui Jang 21 Female Malaysian 012-4998192 20 , Lorong 13 , Taman Patani Janam Melaka Sungai Dulong
The Problem
I expect the tellg() to either return 7 or 8 since the first line 1800567 which is 7 digits so the stream pointer should be placed after this number and before the string "Ho Rui Jang", but tellg() returns 16. Why is it so?
This seems more like a compiler bug (probably gcc)
With the following Code:-
Following is the output:-
In the image
inpstr.exewas generated fromVisual studio's clwhileinp.exefromg++(gcc version 4.6.1 (tdm-1))