문제

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