std::basic_stringbuf<CharT,Traits,Allocator>::seekpos
From cppreference.com
< cpp | io | basic stringbuf
| protected: virtual pos_type seekpos( pos_type sp, |
||
指定された位置 sp に、可能であれば std::basic_streambuf::gptr および/または std::basic_streambuf::pptr を移動します。
実質的に 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() の単一引数バージョンによって呼び出されます。
[編集] 例
このコードを実行
#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() を呼び出す ( std::basic_streambuf<CharT,Traits> の public メンバ関数) | |
| [virtual] |
入力シーケンス、出力シーケンス、またはその両方で、相対アドレス指定を使用して次のポインタを再配置する (virtual protected member function) |
| [virtual] |
絶対アドレスを使用してファイル位置を再配置します (virtual protected member function of std::basic_filebuf<CharT,Traits>) |
| [virtual] |
入力シーケンス、出力シーケンス、またはその両方で、絶対アドレス指定を使用して次のポインタを再配置する (virtual protected member function of std::strstreambuf) |