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
问题
我期望tellg()
返回7
或8
,因为第一行是7位数字1800567
,所以流指针应该在这个数值后面,字符串"Ho Rui Jang"
之前,但实际上tellg()
返回了16
。为什么会这样?