std::basic_istream::seekg
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
basic_istream& seekg( pos_type pos ); |
||
basic_istream& seekg( off_type off, std::ios_base::seekdir dir); |
||
设定输入位置指示器的当前相关的
streambuf
对象。在失败的情况下,要求setstate(std::ios_base::failbit).原文:
Sets input position indicator of the current associated
streambuf
object. In case of failure, calls setstate(std::ios_base::failbit).首先,清除
1) eofbit
(C++11 起),然后表现为UnformattedInputFunction
,除了gcount()
不受影响。在构造和检查岗哨对象的,原文:
First, clears
eofbit
(C++11 起), then behaves as UnformattedInputFunction
, except that gcount()
is not affected. After constructing and checking the sentry object,设定的输入位置指示器绝对(相对于开头的文件)的值
2) pos
。具体来说,执行rdbuf()->pubseekpos(pos, std::ios_base::in).原文:
sets the input position indicator to absolute (relative to the beginning of the file) value
pos
. Specifically, executes rdbuf()->pubseekpos(pos, std::ios_base::in).设定输入位置指示器位置
off
,相对位置,所定义dir
。具体来说,执行rdbuf()->pubseekoff(off, dir, std::ios_base::in). 原文:
sets the input position indicator to position
off
, relative to position, defined by dir
. Specifically, executes rdbuf()->pubseekoff(off, dir, std::ios_base::in). 目录 |
[编辑] 参数
pos | - | 绝对位置设置输入位置指示器.
原文: absolute position to set the input position indicator to. | ||||||||||||||||
off | - | 相对位置设置输入位置指示器.
原文: relative position to set the input position indicator to. | ||||||||||||||||
dir | - | 定义应用的相对偏移量的基础地位。它可以是以下常量之一:
|
[编辑] 返回值
*this
[编辑] 示例
#include <iostream> #include <string> #include <sstream> int main() { std::string str = "Hello, world"; std::istringstream in(str); std::string word1, word2; in >> word1; in.seekg(0); // rewind in >> word2; std::cout << "word1 = " << word1 << '\n' << "word2 = " << word2 << '\n'; }
输出:
word1 = Hello, word2 = Hello,
[编辑] 另请参阅
返回输入位置指示器 原文: returns the input position indicator (公共成员函数) | |
返回的输出位置指示器 原文: returns the output position indicator (公共成员函数of std::basic_ostream )
| |
设置输出位置指示器 (公共成员函数of std::basic_ostream )
|