Namespaces
Variants

std::ios_base:: seekdir

From cppreference.net
typedef /*implementation defined*/ seekdir ;
static constexpr seekdir beg = /*implementation defined*/

static constexpr seekdir end = /*implementation defined*/

static constexpr seekdir cur = /*implementation defined*/

ファイルシーク方向のタイプを指定します。以下の定数が定義されています:

定数 説明
beg ストリームの先頭
end ストリームの末尾
cur ストリーム位置指示子の現在位置

#include <iostream>
#include <sstream>
#include <string>
int main()
{
    std::istringstream in("Hello, World!");
    std::string word1, word2, word3, word4, word5;
    in >> word1;
    in.seekg(0, std::ios_base::beg); // <- 巻き戻し
    in >> word2;
    in.seekg(1, std::ios_base::cur); // -> 現在位置から終端方向へシーク
    in >> word3;
    in.seekg(-6, std::ios_base::cur); // <- 現在位置(終端)から先頭方向へシーク
    in >> word4;
    in.seekg(-6, std::ios_base::end); // <- 終端から先頭方向へシーク
    in >> word5;
    std::cout << "word1 = " << word1 << '\n'
              << "word2 = " << word2 << '\n'
              << "word3 = " << word3 << '\n'
              << "word4 = " << word4 << '\n'
              << "word5 = " << word5 << '\n';
}

出力:

word1 = Hello,
word2 = Hello,
word3 = World!
word4 = World!
word5 = World!

関連項目

入力位置指示子を設定する
( std::basic_istream<CharT,Traits> の公開メンバ関数)
出力位置指示子を設定する
( std::basic_ostream<CharT,Traits> の公開メンバ関数)
seekoff ( ) を呼び出す
( std::basic_streambuf<CharT,Traits> の公開メンバ関数)