[sclug] C++ Quickie

Derek M Jones derek at knosof.co.uk
Wed Dec 10 13:45:41 UTC 2003


>I am trying to persist the place where a file is open (the 'data' file). 
>Basically I am getting an fpos_t of the current place that I am in the data 
>file and writing it to another file (my 'bookmark' file). When I read the 
>position back from the bookmark  file and want to restore my position in the
>data file, fscan it from the bookmark file and get it as an int. How do I 
>convert the int back to an fpos_t so that I can use it to set the filepos?

fpos_t is a type capable of holding all the information capable of
representing a position in a file.
There is no requirement that fpos_t be an integer type, or even that
the same position in a file be represented by the same value (of type
fpos_t) in two different programs (so writing it out and reading it
back in later is not required to work, although it practice it is likely to).

On some systems fpos_t is an aggregate type.  So your best bet is to
write/read it out/in using sizeof and fwrite/fread.


Derek M Jones                                           tel: +44 (0) 1252 520 667
Knowledge Software Ltd                            mailto:derek at knosof.co.uk
Applications Standards Conformance Testing   http://www.knosof.co.uk

More information about the Sclug mailing list