#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
ifstream a("test.txt");
string x;
a >> x;
cout << x << endl;
a >> x;
cout << x << endl;
a.seekg(a.tellg()); // Problem lies here.
a >> x;
cout << x << endl;
a >> x;
cout << x << endl;
return 0;
}
If the a.seekg(a.tellg()) is present, the output is
a
b
d
e
However, if I get rid of it, the output is
a
b
c
d
Is there a more reliable way to use tellg and seekg, or am I using the wrong methods? If I save the tellg value to a variable and later use it in seekg to come back, it also doesn't go to the correct position.