If you're going back and forth like that a lot you might be better of loading the file into some sort of structure, an array or maybe a list. This allows back and forth access much more easily.
tinstaafl
Nearly a Posting Virtuoso
1,324 posts since Jun 2010
Reputation Points: 355
Solved Threads: 228
Skill Endorsements: 14
The extraction operator (>>) should have nothing to do with your error because seekg(0, ios::beg) is modifying the internal stream pointer.
For example, the code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f ("example.txt");
int x, y;
for (int i=0; i<3; i++) {
f >> x >> y;
cout << x << " " << y << endl;
f.seekg(0, ios::beg);
};
f.close();
return 0;
}
where "example.txt" is:
1 2 9
3 4 10
5 6 11
7 8 12
with or without the third column, returns
1 2
1 2
1 2
Could you provide more details about your code?
CGSMCMLXXV
Junior Poster in Training
54 posts since Jan 2013
Reputation Points: 5
Solved Threads: 7
Skill Endorsements: 0