移动在读取流中的位置。
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)。
备注
第一个成员函数执行绝对,找到函数执行相对搜索的第二个成员。
备注
因为 C++ 标准不支持在文本文件的相对,搜索不用于文本文件的第二个成员函数。
失败 如果为 false,某些 pos_type 临时对象的 newpos第一个成员函数调用 newpos -> = rdbufpubseekpos(pos),还是表示。 如果 失败 是错误的,第二个函数调用 newpos = rdbuf ->pubseekoff(off,way)。 在任何情况下,如果,newpos (==) (off_type)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;
}
Enter:basic_istream_seekg.txt
0123456789
Output
2
要求
页眉: <istream>
命名空间: std