It is necessary to read from the binary file the numbers that are on even positions. You need to use seekg (), but how can it work, can you explain? What you need to put instead of dots?

while (!f.eof()) { f.seekg(........, ios::beg); } 
  • The offset from the position you specified as the second parameter. ru.cppreference.com/w/cpp/io/basic_istream/seekg - Harry
  • @Harry, do not quite understand. How to make seekg only on even positions? - IWProgrammer
  • So ... have to start over. What is an even number, you know? - Harry

1 answer 1

The ios::beg modifier sets the pointer to a position from the beginning of the stream. And you need to use ios::cur to shift from the current position. If after reading it is shifted by 1 from the current position, then the parity of the position will not change.

Total

 f.seekg(1, ios::cur); 
  • I think that by "even positions" I mean not absolute positions in files, but positions of numbers in a sequence. So you will not read the numbers, but some kind of ... - Harry