1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
以上是我的代码和结果,我这个程序的目的是每次读取文件中的512个字节,输出是首先输出这个文件的总字节数,然后每次读的时候输出所读入的字节数以及当前get 流指针的位置。
我第一次读512字节之后,当前get流指针的位置不应该是512吗,为什么这个程序却跑出了533的结果?
阿神2017-04-17 13:04:47
There is an answer on Stackoverflow (http://stackoverflow.com/questions/22984956/tellg-function-give-wrong-size-of-file)
The main meaning is that the number returned to you by tellg is not used to calculate the size, but is used when you want to seek the same place in the future. It also gives a correct method to calculate the file size:
1 2 3 4 |
|