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

std::basic_stringbuf::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...

有效执行seekoff(off_type(sp),std::ios_base::beg, which)...

参数

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

返回值

sp关于成功或pos_type(off_type(-1))在失败的时候。

注记

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

二次

代码语言:javascript
复制
#include <sstream>
#include <iostream>
 
struct mybuf : std::stringbuf
{
    mybuf(const std::string& str) : std::stringbuf(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::stringbuf::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)

seekoff virtual

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

seekpos virtual

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

seekpos virtual

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

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com