Cpp-standard-library-cpp-basic-ios-seekg
提供:Dev Guides
C ++ basic_iosライブラリ-seekg
説明
入力シーケンスの位置を設定するために使用されます。
宣言
- 以下は、std
- basic_istream :: seekgの宣言です。
(1) basic_istream& seekg (pos_type pos);
(2) basic_istream& seekg (off_type off, ios_base::seekdir way);
パラメーター
- pos -ストリーム内の新しい絶対位置(先頭からの相対位置)。
- off -wayパラメータに関連するオフセット値。
- way -タイプios_base :: seekdirのオブジェクト。
戻り値
basic_istreamオブジェクト(* this)を返します。
例外
基本保証-例外がスローされた場合、オブジェクトは有効な状態です。
データの競合
ストリームオブジェクトを変更します。
例
- 以下のstd
- basic_istream :: seekgの例。
#include <iostream>
#include <fstream>
int main () {
std::ifstream is ("test.txt", std::ifstream::binary);
if (is) {
is.seekg (0, is.end);
int length = is.tellg();
is.seekg (0, is.beg);
char * buffer = new char [length];
is.read (buffer,length);
is.close();
std::cout.write (buffer,length);
delete[] buffer;
}
return 0;
}