rewind() 到底做了什么?
What exactly does rewind() do?
我在 C 中遇到了 rewind()
函数。我从 here 中查看了它的描述和示例。
描述中提到了以下关于函数的内容:
The C library function void rewind(FILE *stream)
sets the file position to the beginning of the file of the given stream.
我真的还没想清楚。我们可以把它想象成一个光标在要读取的文件中移动,rewind()
只是将光标设置到文件的开头吗?
来自man page:
The rewind() function sets the file position indicator for the stream pointed to by stream to the beginning of the file. It is equivalent to:
(void)fseek(stream, 0L, SEEK_SET)
except that the error indicator for the stream is also cleared (see
clearerr(3)
).
因此,下次您在调用 rewind
后读取文件时,您会从头开始读取。所以你的光标类比是有效的。
我在 C 中遇到了 rewind()
函数。我从 here 中查看了它的描述和示例。
描述中提到了以下关于函数的内容:
The C library function
void rewind(FILE *stream)
sets the file position to the beginning of the file of the given stream.
我真的还没想清楚。我们可以把它想象成一个光标在要读取的文件中移动,rewind()
只是将光标设置到文件的开头吗?
来自man page:
The rewind() function sets the file position indicator for the stream pointed to by stream to the beginning of the file. It is equivalent to:
(void)fseek(stream, 0L, SEEK_SET)
except that the error indicator for the stream is also cleared (see
clearerr(3)
).
因此,下次您在调用 rewind
后读取文件时,您会从头开始读取。所以你的光标类比是有效的。