std::basic_stringbuf<CharT,Traits,Allocator>::seekpos
提供: cppreference.com
<tbody>
</tbody>
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 | - | seekoff() や seekpos() などで取得したストリームの位置
| ||||||
| which | - | 入力シーケンス、出力シーケンス、またはその両方のいずれに影響を与えるかを定義します。 以下の定数のいずれかまたは組み合わせを指定できます。
|
戻り値
成功した場合は sp、失敗した場合は pos_type(off_type(-1))。
ノート
seekpos() は std::basic_streambuf::pubseekpos() によって呼ばれ、それは std::basic_istream::seekg() および std::basic_ostream::seekp() の1引数バージョンによって呼ばれます。
例
Run this code
#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
関連項目
seekpos() を呼びます ( std::basic_streambuf<CharT,Traits>のパブリックメンバ関数)
| |
[仮想] |
入力シーケンス、出力シーケンス、または両方の次ポインタの位置を、相対位置を用いて再設定します (仮想プロテクテッドメンバ関数) |
[仮想] |
絶対位置を使用してファイル位置を再設定します ( std::basic_filebuf<CharT,Traits>の仮想プロテクテッドメンバ関数)
|
[仮想] |
入力シーケンス、出力シーケンス、またはその両方の次ポインタの位置を絶対位置を用いて再設定します ( std::strstreambufの仮想プロテクテッドメンバ関数)
|