gpt4 book ai didi

c - 为什么 C 文件流的开头称为 `SEEK_SET` ?

转载 作者:太空宇宙 更新时间:2023-11-04 05:47:35 25 4
gpt4 key购买 nike

您可以在 fseek 等函数中使用三个 origin 常量来确定从何处计算您的 offset:SEEK_SETSEEK_CURSEEK_ENDSEEK_CURSEEK_END 似乎不言自明地表示文件流的当前位置和结尾,但为什么 SEEK_SET 用来表示开头?为什么不是像 SEEK_BEG 这样的东西?

最佳答案

因为你可以添加一个偏移量。通过使用 SEEK_SET,您可以显式设置偏移量。 (通过将其添加到开头)

来自 fseek 的联机帮助页:

The new position, measured in bytes, is
obtained by adding offset bytes to the position specified by whence.
If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is
relative to the start of the file, the current position indicator, or
end-of-file, respectively.

来自 lseek 的联机帮助页:

   SEEK_SET
The file offset is set to offset bytes.

SEEK_CUR
The file offset is set to its current location plus offset
bytes.

SEEK_END
The file offset is set to the size of the file plus offset
bytes.

关于c - 为什么 C 文件流的开头称为 `SEEK_SET` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56433377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com