basic_istream::seekg
ストリームの読み取り専用位置を移動します。
basic_istream<Elem, Tr>& seekg(
pos_type pos
);
basic_istream<Elem, Tr>& seekg(
off_type off,
ios_base::seekdir way
);
パラメーター
pos
入力ポインターを動かした絶対位置。off
入力ポインター相対的な wayを移動するためのオフセット。way
ios_base::seekdir の列挙体の 1 つがあります。
戻り値
ストリーム (*this)。
解説
一つ目のメンバー関数は、絶対シークが、2 番目のメンバー関数実行相対シークを実行します。
注意
標準 C++ はテキスト ファイルの相対的なシークをサポートしないため、テキスト ファイルに対して、2 番目のメンバー関数は使用しないでください。
失敗 が false の場合、pos_type の一時オブジェクト newposの最初のメンバー関数の呼び出し newpos = rdbuf ->pubseekpos (pos)。 失敗 が false の場合、2 番目の関数呼び出し newpos = rdbuf ->pubseekoff (off、way)。 いずれの場合も、(off_type) newpos == (off_type) (- 1) (位置操作は失敗する)、関数呼び出し istr。setstate (failbit)。 どちらの関数を返します。*this。
失敗 が true の場合は、メンバー関数は、何も行いません。
使用例
// basic_istream_seekg.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>
int main ( )
{
using namespace std;
ifstream file;
char c, c1;
file.open( "basic_istream_seekg.txt" );
file.seekg(2); // seek to position 2
file >> c;
cout << c << endl;
}
入力: basic_istream_seekg.txt
0123456789
出力
2
必要条件
ヘッダー: の <istream>
名前空間: std