When using seekg, what parameter does seekg take. I read that it takes the position, but in the code below, using 1 or 2 for the seekg parameter gives the same result.

ifstream input ("numbers.in");
input.seekg(1);
int a;
input >> a;
cout << a;

Textfile is: 9 8 7 6

Whether I use 1 or 2 for seekg() I get 8. Why is this, and how do I fix it?

有帮助吗?

解决方案

What do you want to fix?

1 points to

9 8 7 6
 ^

and 2 points to

9 8 7 6
  ^

so both will read 8 as next int.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top