名前空間
変種
操作

std::basic_stringbuf<CharT,Traits,Allocator>::seekpos

提供: cppreference.com
< cpp‎ | io‎ | basic stringbuf
 
 
入出力ライブラリ
入出力マニピュレータ
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 によって示される位置に再設定します。

実質的に seekoff(off_type(sp), std::ios_base::beg, which) を実行します。

目次

[編集] 引数

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

[編集] 戻り値

成功した場合は sp、失敗した場合は pos_type(off_type(-1))

[編集] ノート

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

[編集]

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