I read this in one of Perl manuals, but it is easily translated into standard C, which, in turn, can be translated to istream
s.
seek FILEHANDLE,POSITION,WHENCE
Sets FILEHANDLE's position, just like the "fseek" call of
"stdio".
<...>
A WHENCE of 1 ("SEEK_CUR") is useful for not moving the file
position:
seek(TEST,0,1);
This is also useful for applications emulating "tail -f". Once
you hit EOF on your read, and then sleep for a while, you might
have to stick in a seek() to reset things. The "seek" doesn't
change the current position, but it does clear the end-of-file
condition on the handle, so that the next "<FILE>" makes Perl
try again to read something. We hope.
As far as I remember, fseek
is called iostream::seekg
. So you should basically do the same: seek to the end of the file, then sleep and seek again with ios_base::cur
flag to update end-of-file and read some more data.
Instead of sleep
ing, you may use inotify, as suggested in the other answer, to sleep (block while reading from an emulated file, actually) exactly until the file is updated/closed. But that's Linux-specific, and is not standard C++.
ios_base::openmode
doesn't have anything like it. What am I missing? – Hardtop