Share via


basic_filebuf::seekoff

Tries to alter the current positions for the controlled streams.

virtual pos_type seekoff( 
   off_type _Off, 
   ios_base::seekdir _Way, 
   ios_base::openmode _Which = ios_base::in | ios_base::out 
);

Parameters

  • _Off
    The position to seek for relative to _Way.

  • _Way
    The starting point for offset operations. See seekdir for possible values.

  • _Which
    Specifies the mode for the pointer position. The default is to allow you to modify the read and write positions.

Return Value

Returns the new position or an invalid stream position.

Remarks

The protected virtual member function endeavors to alter the current positions for the controlled streams. For an object of class basic_filebuf<Elem, Tr>, a stream position can be represented by an object of type fpos_t, which stores an offset and any state information needed to parse a wide stream. Offset zero designates the first element of the stream. (An object of type pos_type stores at least an fpos_t object.)

For a file opened for both reading and writing, both the input and output streams are positioned in tandem. To switch between inserting and extracting, you must call either pubseekoff or pubseekpos. Calls to pubseekoff (and hence to seekoff) have various limitations for text streams, binary streams, and wide streams.

If the file pointer fp is a null pointer, the function fails. Otherwise, it endeavors to alter the stream position by calling fseek(fp, _Off, _Way). If that function succeeds and the resulting position fposn can be determined by calling fgetpos(fp, &fposn), the function succeeds. If the function succeeds, it returns a value of type pos_type containing fposn. Otherwise, it returns an invalid stream position.

Requirements

Header: <fstream>

Namespace: std

See Also

Reference

basic_filebuf Class

iostream Programming

iostreams Conventions