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 |
返回值
sp
关于成功或pos_type(off_type(-1))
在失败的时候。
注记
seekpos()
被std::basic_streambuf::pubseekpos()
的单参数版本调用std::basic_istream::seekg()
和std::basic_ostream::seekp()
...
例
二次
#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
}
二次
产出:
二次
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) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。