首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::strstreambuf::seekpos

protected: virtual pos_type seekpos(pos_type sp, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out );

?

?

再定位std::basic_streambuf::gptr和/或std::basic_streambuf::pptr,如果可能的话,按照sp...

如果std::ios_base::in设为which,试图重新定位gptr()%28获取区域%29中的下一个指针。如果std::ios_base::out设为which,试图重新定位pptr()%28是PUT区域%29中的下一个指针。如果没有设置位which操作失败。

每个下一个指针被重新定位如下:

1%29如果下一个指针为空,则操作失败。

2%29否则,新的冲销newoff28%类型off_type%29是通过调用sp.offset().如果newoff为负,超出缓冲区的界限,或无效,操作失败。

3%29否则,下一个指针将被赋值为gptr() = eback()+newoffpptr() = pbase()+newoff...

参数

sp

-

stream position, such as one obtained by seekoff() or seekpos()

which

-

defines whether the input sequences, the output sequence, or both are affected. It can be one or a combination of the following constants: Constant Explanation in affect the input sequence out affect the output sequence

Constant

Explanation

in

affect the input sequence

out

affect the output sequence

Constant

Explanation

in

affect the input sequence

out

affect the output sequence

返回值

结果偏移量转换为pos_type关于成功或pos_type(off_type(-1))在失败的时候。

注记

seekpos()std::basic_streambuf::pubseekpos()的单参数版本调用std::basic_istream::seekg()std::basic_ostream::seekp()...

二次

代码语言:javascript
复制
#include <strstream>
#include <cstring>
#include <iostream>
 
struct mybuf : std::strstreambuf
{
    mybuf(const char* str) : std::strstreambuf(str, std::strlen(str)) {}
    pos_type seekpos(pos_type sp, std::ios_base::openmode which) {
         std::cout << "Before seekpos(" << sp << "), size of the get area is "
                   << egptr()-eback() << " with "
                   << egptr()-gptr() << " read positions available\n";
         pos_type rc = std::strstreambuf::seekpos(sp, which);
         std::cout << "seekpos() returns " << rc << ".\nAfter the call, "
                   << "size of the get area is "
                   << egptr()-eback() << " with "
                   << egptr()-gptr() << " read positions available\n";
        return rc;
    }
};
 
int main()
{
    mybuf buf("12345");
    std::iostream stream(&buf);
    stream.seekg(2);
}

二次

产出:

二次

代码语言:javascript
复制
Before seekpos(2), size of the get area is 5 with 5 read positions available
seekpos() returns 2.
After the call, size of the get area is 5 with 3 read positions available

二次

另见

pubseekpos

invokes seekpos() (public member function of std::basic_streambuf)

seekpos virtual

repositions the next pointer in the input sequence, output sequence, or both using absolute addressing (virtual protected member function of std::basic_stringbuf)

seekpos virtual

repositions the file position, using absolute addressing (virtual protected member function of std::basic_filebuf)

seekoff virtual

repositions the next pointer in the input sequence, output sequence, or both, using relative addressing (virtual protected member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com