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