std::basic_stringbuf<CharT,Traits,Allocator>:: seekpos
|
protected
:
virtual
pos_type seekpos
(
pos_type sp,
|
||
std::basic_streambuf::gptr および/または std::basic_streambuf::pptr を、可能であれば sp で示される位置に再配置します。
seekoff ( off_type ( sp ) , std:: ios_base :: beg , which ) を効果的に実行します。
目次 |
パラメータ
| sp | - |
ストリーム位置、
seekoff()
または
seekpos()
によって取得されるもの
|
||||||
| which | - |
入力シーケンス、出力シーケンス、またはその両方が影響を受けるかを定義する。以下の定数の1つまたは組み合わせを指定可能:
|
戻り値
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.
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 375 | C++98 |
std::ios_base
の静的定数メンバが
std::basic_ios のメンバとして誤って指定されていた |
修正済み |
| LWG 564 | C++98 |
gptr
および
pptr
の再配置方法が不明確だった
|
seekoff() によって再配置される |
関連項目
seekpos
を呼び出す
seekpos
(
)
(
std::basic_streambuf<CharT,Traits>
のpublicメンバ関数)
|
|
|
[virtual]
|
相対アドレッシングを使用して、入力シーケンス、出力シーケンス、または両方の次のポインタを再配置する
(仮想protectedメンバ関数) |
|
[virtual]
|
絶対アドレッシングを使用してファイル位置を再配置する
(
std::basic_filebuf<CharT,Traits>
の仮想protectedメンバ関数)
|
|
[virtual]
|
絶対アドレッシングを使用して入力シーケンス、出力シーケンス、または両方の次のポインタを再配置する
(
std::strstreambuf
の仮想protectedメンバ関数)
|