I am trying to read from file using fstream .The file I am trying to read has this content:
1200 1000 980 890 760 My code:
#include <fstream> #include <iostream> using namespace std; int main () { fstream file("highscores.txt", ios::in | ios::out); if (!file.is_open()) { cout << "Could not open file!" << endl; return 0; } int cur_score; while (!file.eof()) { file >> cur_score; cout << file.tellg() << endl; } } The output is:
9 14 18 22 26 Why after first read the tellg() returns 9, the first read is the number (1200) which is 4 positions and I know there is \r and \n so this make 6 positions. Also. if I add more number in my file tellg() will return a bigger number after first read.
while(!file.eof()).