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 列舉型別。
傳回值
資料流 (*this)。
備註
第 10% 成員函式執行絕對搜尋,函式執行相對搜尋的第二個成員。
注意事項 |
---|
,因為 Standard C++ 不支援在文字檔中,的相對搜尋不想要使用的文字檔的第二 + 成成員函式。 |
如果 失敗 為 false,第 10% 成員函式呼叫 (Function Call) newpos = rdbuf - > pubseekpos(pos),某些 pos_type 暫存物件的 newpos。如果 fail 為 false,第二個函式呼叫 newpos = rdbuf - > pubseekoff(off, way)。不論是哪一種,因此,如果off_type(==)newpos (off_type) (- 1) (定位作業失敗),函式會 istr。setstate(failbit)。兩個函式傳回 *this。
如果 失敗 成立,成員函式不會執行任何動作。
範例
// 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
Output
2
需求
標題: <istream>
命名空間: std