protected virtual member function
<fstream>
pos_type seekoff (off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out);
Set internal position to relative position
Sets a new position for the internal position pointers specified by parameter which. This position is calculated as an offset of off characters relative to a the origin specified by way.
Unless off is zero and way is cur, the function also writes any unwritten characters in the intermediate output buffer to the file (also calling unshift using the proper facet, when needed).
When successful, this function has the same effects as the equivalent call to fseek (see fseek for details and limitations, such as on files open in text mode).
This virtual function is called by the public member basic_streambuf::pubseekoff.
Parameters
- off
- Offset value, relative to the way parameter.
If the stream uses a variable-width or state-dependent encoding, off shall be zero (otherwise, the function fails).
Member type off_type is determined by the character traits: generally, it is an alias of the signed integral type streamoff.
- way
- Object of type ios_base::seekdir, indicating the origin from which the offset is applied. It may take any of the following constant values:
value | offset is relative to... |
ios_base::beg | beginning of the file |
ios_base::cur | current position of either the input position or the output position, depending on argument which.
|
ios_base::end | end of the file |
- which
- Determines which of the internal position pointers is affected: the input position, the output position, or both. It is an object of type ios_base::openmode that, for this function, may take any combination of the following significant constant values:
value | position pointer affected |
ios_base::in | Modifies the input position, and its corresponding get pointer (gptr) |
ios_base::out | Modifies the output position and its corresponding put pointer (pptr) |
Both positions may be selected simultaneously, but if both are selected when way is ios_base::cur, the function fails.
Return Value
On success, it returns the new absolute position the internal position pointer points to after the call, if representable as a value of member type pos_type.
On failure, or if the above is not possible, the function returns pos_type(off_type(-1))
.
Member type pos_type is determined by the character traits: generally, it is an fpos type (such as streampos) that can be converted to/from integral types.
Data races
Modifies the basic_filebuf object.
Concurrent access to the same file stream buffer object may introduce data races.
Exception safety
Basic guarantee: if an exception is thrown, the file stream buffer is in a valid state.