std::basic_spanbuf<CharT,Traits>::seekoff
来自 cppreference.cn
< cpp | io | basic spanbuf
protected: pos_type seekoff( off_type off, std::ios_base::seekdir dir, |
(since C++23) | |
如果可能,将get和/或put区域的下一个指针重定位到与缓冲区get和/或put区域的起始位置、结束位置或当前位置偏移 off
个字符的位置。
设 n
为底层缓冲区中 CharT
元素的数量,或者在没有底层缓冲区时为 0,如果发生以下情况,此函数将失败:
- 要重定位的get和/或put区域的下一个指针为空,并且计算出的
newoff
(见下文) 不为零,这可能发生在没有底层缓冲区时,或者 *this 没有以which
要求的模式打开,或者 -
dir
为 std::ios_base::cur 且 std::ios_base::in 和 std::ios_base::out 都设置在which
中,或者 - 计算出的
newoff
不能用off_type
表示,小于零,或大于n
。
newoff
的计算如下
- 如果
dir
为 std::ios_base::beg,则newoff
为off
。 - 如果
dir
为 std::ios_base::cur,则newoff
为- pptr() - pbase() + off 如果 std::ios_base::out 设置在
which
中,或者 - gptr() - eback() + off 如果 std::ios_base::in 设置在
which
中。
- pptr() - pbase() + off 如果 std::ios_base::out 设置在
- 如果
dir
为 std::ios_base::end,则newoff
为- pptr() - pbase() + off 如果 std::ios_base::out 但不是 std::ios_base::in 设置在 *this 的打开模式中,
- 否则, off + n。
如果 std::ios_base::in 和/或 std::ios_base::out 在 which
中相应地设置,此函数成功时将 get 和/或 put 区域的下一个指针重定位到 pbuf + newoff,其中 pbuf
是指向底层缓冲区开头的指针,或者在没有底层缓冲区时为空指针值。
内容 |
[编辑] 参数
off | - | 设置下一个指针的相对位置 | ||||||||
dir | - | 定义应用相对偏移量的基准位置。它可以是以下常量之一
| ||||||||
which | - | 定义输入序列、输出序列或两者是否受影响。它可以是以下常量之一或组合
|
[编辑] 返回值
pos_type(newoff) 成功时返回 pos_type(newoff),失败时返回 pos_type(off_type(-1))。
[编辑] 示例
本节不完整 原因:没有示例 |
[编辑] 参见
[虚函数] |
使用相对寻址重定位输入序列、输出序列或两者的下一个指针 (std::basic_stringbuf<CharT,Traits,Allocator> 的虚保护成员函数) |
[虚函数] |
使用相对寻址重定位输入序列、输出序列或两者的下一个指针 (std::strstreambuf 的虚保护成员函数) |