what's the difference between `fseek`, `lseek`, `seekg`, `seekp`?

后端 未结 1 942
难免孤独
难免孤独 2020-12-25 13:38

I was asked by an interviewer that how would I implement tail (yes, the one in linux shell). My answer was, first seek to the end of the file, then read charact

相关标签:
1条回答
  • 2020-12-25 14:00

    Use seekg when using the C++ IOstreams library. seekp is no use here, since it sets the put pointer.

    Use fseek when using the C stdio library. Use lseek when using low-level POSIX file descriptor I/O.

    The difference between the various seek functions is just the kind of file/stream objects on which they operate. On Linux, seekg and fseek are probably implemented in terms of lseek.

    0 讨论(0)
提交回复
热议问题