The contents of the file are "hello world foo(int) a=b".
The code is
#include <iostream>
using namespace std;
#include <fstream>
int main()
{
ifstream Infile;
char c;
Infile.open("Input.txt");
if (Infile.is_open())
{
Infile.seekg(0, ios::beg);
while (!Infile.eof())
{
cout << Infile.tellg() << ' ';
Infile.get(c);
}
}
return 0;
}
The output of the program is
0 2 4 6 8 10 12 14 16 18 20 22 24 26
However, should'nt it be
0 1 2 3 4 5 6 7 8 9 10 11 12 13 and so on....
Because I am reading one character at a time and from what I know, the get(char) function also reads whitespaces and endlines...
I don't understand why the position pointer is being incremented by two and not one!!? However if manipulate the pointer using seekg() func, it returns the character at that position but If i use tellg() and just read input, then it increments the pointer by two...
Any clues?