Cpp-standard-library-cpp-basic-ios-tellg

提供:Dev Guides
移動先:案内検索

C ++ basic_iosライブラリ-tellg

説明

入力シーケンスの位置を取得するために使用されます。

宣言

以下は、std
basic_istream :: tellgの宣言です。
pos_type tellg();

パラメーター

none

戻り値

ストリーム内の現在の位置を返します。

例外

基本保証-例外がスローされた場合、オブジェクトは有効な状態です。

データの競合

ストリームオブジェクトを変更します。

以下のstd
basic_istream :: tellgの例。
#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;
}