Share via


fpos

fpos

template <class St>
    class fpos {
public:
    fpos(St state, fpos_t fposn);
    fpos(streamoff off);
    fpos_t get_fpos_t() const;
    St state() const;
    void state(St state);
    operator streamoff() const;
    streamoff operator-(const fpos<St>& rhs) const;
    fpos<St>& operator+=(streamoff off);
    fpos<St>& operator-=(streamoff off);
    fpos<St> operator+(streamoff off) const;
    fpos<St> operator-(streamoff off) const;
    bool operator==(const fpos<St>& rhs) const;
    bool operator!=(const fpos<St>& rhs) const;
    };

The template class describes an object that can store all the information needed to restore an arbitrary file-position indicator within any stream. An object of class fpos<St> effectively stores three member objects:

  • A byte offset, of type streamoff
  • An arbitrary file position, for use by an object of class basic_filebuf, of type fpos_t
  • A conversion state, for use by an object of class basic_filebuf, of type St, typically mbstate_t

For an environment with limited file size, however, streamoff and fpos_t may sometimes be used interchangeably. And for an environment with no streams that have a state-dependent encoding, mbstate_t may actually be unused. So the number of member objects stored may well vary from one to three.