std::basic_stringbuf<CharT,Traits,Allocator>::seekoff (3) - Linux Manuals
std::basic_stringbuf<CharT,Traits,Allocator>::seekoff: std::basic_stringbuf<CharT,Traits,Allocator>::seekoff
NAME
std::basic_stringbuf<CharT,Traits,Allocator>::seekoff - std::basic_stringbuf<CharT,Traits,Allocator>::seekoff
Synopsis
protected:
virtual pos_type seekoff(off_type off,
ios_base::seekdir dir,
ios_base::openmode which = ios_base::in | ios_base::out);
Repositions std::basic_streambuf::gptr and/or std::basic_streambuf::pptr, if possible, to the position that corresponds to exactly off characters from beginning, end, or current position of the get and/or put area of the buffer.
* If which includes ios_base::in and this buffer is open for reading (that is, if ((which & ios_base::in) == ios_base::in), then repositions the read pointer std::basic_streambuf::gptr inside the get area as described below
* If which includes ios_base::out and this buffer is open for writing (that is, (which & ios_base::out) == ios_base::out), then repositions the write pointer std::basic_streambuf::pptr inside the put area as described below
* If which includes both ios_base::in and ios_base::out and the buffer is open for both reading and writing ((which & (ios_base::in|ios_base::out)) ==(ios_base::in|ios_base::out)), and dir is either ios_base::beg or ios_base::end, then repositions both read and write pointers as described below.
* Otherwise, this function fails.
If the pointer (either gptr or pptr or both) is repositioned, it is done as follows:
1) If the pointer to be repositioned is a null pointer and the new offset newoff would be non-zero, this function fails.
2) The new pointer offset newoff of type off_type is determined
a) if dir == ios_base::beg, then newoff is zero
b) if dir == ios_base::cur, then newoff is the current position of the pointer (gptr()-eback() or pptr()-pbase())
c) if dir == ios_base::end, then newoff is the length of the entire initialized part of the buffer (if overallocation is used, the high watermark pointer minus the beginning pointer)
3) If newoff + off < 0 (the repositioning would move the pointer to before the beginning of the buffer) or if newoff + off would point past the end of the buffer (or past the last initialized character in the buffer if overallocation is used), the function fails
4) Otherwise, the pointer is assigned as if by gptr() = eback() + newoff + off or pptr() = pbase() + newoff + off
Parameters
off - relative position to set the next pointer(s) to
dir - beg the beginning of a stream
which - Constant Explanation
Return value
pos_type(newoff) on success, pos_type(off_type(-1)) on failure and if pos_type cannot represent the resulting stream position.
Example
// Run this code
Output:
See also
seekpos repositions the next pointer in the input sequence, output sequence, or both using absolute addressing
[virtual]
seekoff repositions the next pointer in the input sequence, output sequence, or both, using relative addressing
[virtual]
seekoff repositions the file position, using relative addressing