std::basic_istream<CharT,Traits>::seekg
提供: cppreference.com
< cpp | io | basic istream
basic_istream& seekg( pos_type pos ); |
||
basic_istream& seekg( off_type off, std::ios_base::seekdir dir); |
||
現在紐付けられている streambuf
オブジェクトの入力位置指示子を設定します。 失敗した場合は setstate(std::ios_base::failbit) を呼びます。
他のいかなることもする前に eofbit をクリアします。 |
(C++11以上) |
seekg
は UnformattedInputFunction として動作しますが、 gcount() は影響を受けません。 sentry オブジェクトの構築および確認の後、
1) 入力位置指示子を絶対 (ファイルの先頭からの相対) 位置
pos
に設定します。 具体的には rdbuf()->pubseekpos(pos, std::ios_base::in) を実行します。目次 |
[編集] 引数
pos | - | 入力位置指示子を設定する絶対位置 | ||||||||
off | - | 入力位置指示子を設定する相対位置 | ||||||||
dir | - | 相対オフセットを適用するベースの位置を定義します。 以下の定数のいずれかを指定できます。
|
[編集] 戻り値
*this。
[編集] 例外
���部の操作が例外を投げた場合、それはキャッチされ、 badbit がセットされます。 exceptions() が badbit
に対してセットされていれば、その例外が投げ直されます。
[編集] 例
Run this code
#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,
[編集] 関連項目
入力位置指示子を返します (パブリックメンバ関数) | |
出力位置指示子を返します ( std::basic_ostream<CharT,Traits> のパブリックメンバ関数)
| |
出力位置指示子を設定します ( std::basic_ostream<CharT,Traits> のパブリックメンバ関数)
|