std::strstreambuf:: seekoff
|
protected
:
virtual
pos_type seekoff
(
off_type off,
|
(C++98で非推奨)
(C++26で削除) |
|
std::basic_streambuf::gptr および/または std::basic_streambuf::pptr を、可能であればバッファのget領域および/またはput領域の先頭、末尾、または現在位置から正確に off 文字分の位置に再配置します。
- which が ios_base :: in を含み、かつこのバッファが読み取り用にオープンされている場合、以下に説明するようにゲット領域内の読み取りポインタ std::basic_streambuf::gptr を再配置します。
- which が ios_base :: out を含み、かつこのバッファが書き込み用にオープンされている場合、以下に説明するようにプット領域内の書き込みポインタ std::basic_streambuf::pptr を再配置します。
-
which
が
ios_base
::
in
と
ios_base::outの両方を含み、かつバッファが読み取りと書き込みの両方でオープンされており、かつ way が ios_base :: beg または ios_base :: end のいずれかである場合、以下に説明するように読み取りポインタと書き込みポインタの両方を再配置します。 - それ以外の場合、この関数は失敗します。
ポインタ(
gptr
または
pptr
のいずれか、あるいは両方)が再配置される場合、以下のように行われます:
off_type
が決定されます
目次 |
パラメータ
| off | - | 次のポインタの相対位置を設定する | ||||||||
| way | - |
相対オフセットを適用する基準位置を定義します。以下の定数のいずれかを指定できます:
|
||||||||
| which | - |
入力シーケンス、出力シーケンス、またはその両方が影響を受けるかどうかを定義します。以下の定数の1つまたは組み合わせを指定できます:
|
戻り値
pos_type ( newoff ) 成功時、 pos_type ( off_type ( - 1 ) ) 失敗時、およびpos_typeが結果のストリーム位置を表現できない場合。
例
#include <iostream> #include <strstream> int main() { char a[] = "123"; std::strstream ss(a, sizeof a); // in/out std::cout << "put pos = " << ss.tellp() << " get pos = " << ss.tellg() << '\n'; // 両方のポインタを絶対位置指定 ss.rdbuf()->pubseekoff(1, std::ios_base::beg); // 両方を前方に移動 std::cout << "put pos = " << ss.tellp() << " get pos = " << ss.tellg() << '\n'; // 両方のポインタを現在位置から1つ前方に移動しようとする if (-1 == ss.rdbuf()->pubseekoff(1, std::ios_base::cur)) std::cout << "現在位置からの両方のポインタの移動に失敗しました\n"; std::cout << "put pos = " << ss.tellp() << " get pos = " << ss.tellg() << '\n'; // 書き込みポインタを1つ前方に移動(読み取りポインタは移動しない) // ss.seekp(1, std::ios_base::cur); としても呼び出せる ss.rdbuf()->pubseekoff(1, std::ios_base::cur, std::ios_base::out); std::cout << "put pos = " << ss.tellp() << " get pos = " << ss.tellg() << '\n'; ss << 'a'; // put位置に書き込み std::cout << "put位置に'a'を書き込み、バッファは現在: '"; std::cout.write(a, sizeof a); std::cout << "'\n"; char ch; ss >> ch; std::cout << "get位置での読み取り結果は '" << ch << "'\n"; }
出力:
put pos = 0 get pos = 0 put pos = 1 get pos = 1 moving both pointers from current position failed put pos = 1 get pos = 1 put pos = 2 get pos = 1 Wrote 'a' at put position, the buffer is now: '12a' reading at get position gives '2'
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 55 | C++98 |
seekoff
は失敗時に未定義の
無効なストリーム位置を返していた |
pos_type
(
off_type
(
-
1
)
)
が失敗時に返される |
関連項目
|
[virtual]
|
入力シーケンス、出力シーケンス、またはその両方の次のポインタを絶対アドレス指定を使用して再配置する
(仮想保護メンバ関数) |
|
[virtual]
|
入力シーケンス、出力シーケンス、またはその両方の次のポインタを相対アドレス指定を使用して再配置する
(
std::basic_streambuf<CharT,Traits>
の仮想保護メンバ関数)
|
|
[virtual]
|
入力シーケンス、出力シーケンス、またはその両方の次のポインタを相対アドレス指定を使用して再配置する
(
std::basic_stringbuf<CharT,Traits,Allocator>
の仮想保護メンバ関数)
|
|
[virtual]
|
ファイル位置を相対アドレス指定を使用して再配置する
(
std::basic_filebuf<CharT,Traits>
の仮想保護メンバ関数)
|