名前空間
変種
操作

std::strstreambuf::seekpos

提供: cppreference.com
< cpp‎ | io‎ | strstreambuf
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
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 の示す位置に再設定します。

whichstd::ios_base::in がセットされていれば、 gptr() (get 領域の次ポインタ) の再設定を試みます。 whichstd::ios_base::out がセットされていれば、 pptr() (put 領域の次ポインタ) の位置を再設定します。 which にいずれのビットもセットされていなければ、操作は失敗します。

それぞれの次ポインタの位置は以下のように再設定されます。

1) 次ポインタがヌルであれば、操作は失敗します。
2) そうでなければ、 sp.offset() を呼ぶことによって (off_type 型の) 新しいオフセット newoff が決定されます。 newoff が負の場合、バッファの範囲外の場合、または無効な場合、操作は失敗します。
3) そうでなければ、 gptr() = eback()+newoff または pptr() = pbase()+newoff によって行われたかのように、次ポインタが代入されます。


目次

[編集] 引数

sp - ストリーム位置、 seekoff() または seekpos() によって取得されたものなど
which - 入力シーケンス、出力シーケンス、または両方のいずれが影響を受けるかを定義します。 以下の定数のいずれかまたは組み合わせを指定できます。
定数 説明
in 入力シーケンスに影響を与えます
out 出力シーケンスに影響を与えます

[編集] 戻り値

成功した場合は pos_type に変換された結果のオフセット、失敗した場合は pos_type(off_type(-1))

[編集] ノート

seekpos()std::basic_streambuf::pubseekpos() によって呼ばれ、それは std::basic_istream::seekg() および std::basic_ostream::seekp() の単一引数バージョンによって呼ばれます。

[編集]

#include <strstream>
#include <cstring>
#include <iostream>
 
struct mybuf : std::strstreambuf
{
    mybuf(const char* str) : std::strstreambuf(str, std::strlen(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::strstreambuf::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>のパブリックメンバ関数) [edit]
[仮想]
入力シーケンス、出力シーケンス、または両方の次ポインタの位置を、絶対位置を用いて再設定します
(std::basic_stringbuf<CharT,Traits,Allocator>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
絶対位置を使用してファイル位置を再設定します
(std::basic_filebuf<CharT,Traits>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
相対位置を使用して入力シーケンス、出力シーケンス、またはその両方の次ポインタの位置を再設定します
(仮想プロテクテッドメンバ関数) [edit]