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
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
.