为什么 C 文件流的开头称为“SEEK_SET”?

aho*_*ota 2 c io file

有三个origin常量,你可以像使用功能fseek,从您的判断offset数:SEEK_SETSEEK_CUR,和SEEK_ENDSEEK_CUR并且SEEK_END似乎不言自明地表示文件流的当前位置和结尾,但为什么SEEK_SET用来表示开始?为什么不是这样的SEEK_BEG

ste*_*ena 7

因为您可以添加偏移量。通过使用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.
Run Code Online (Sandbox Code Playgroud)

从 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.
Run Code Online (Sandbox Code Playgroud)

  • ...也就是说,使用`SEEK_SET`,文件位置被*设置*为指定的值。 (2认同)
  • 我认为,因为将其设置为一个值更易于理解。“设置”是一种(心理)操作,但添加到开头是更多操作。按照命名模式, SEEK_ADD_CUR 本来是可能的。:) (2认同)