ifstream is ("msg.bin", ios::in | ios::binary); if (is.fail()) assert (!"miss"); // ファイルサイズを調べる is.seekg (0, fstream::end); fstream::streampos end = is.tellg(); is.seekg (0, fstream::beg); ios::pos_type end = file->stream_->tellg(); size_t size = (size_t)end.seekpos(); // 読み込みバッファを確保 char* readBuff = new char [size]; // ファイルサイズより多く読むよう指示 is.read (readBuff, size * 100); // この時点で、 // ios_base::eofbit | ios_base::failbit // のフラグが立ち、以下のテストが失敗する。 // assert (!is.fail()); // 状態がis.fail() であると、seekg や tellg などが機能しなくなる。 // これはかなり分かりにくい仕様になっている is.seekg (0, fstream::end); ios::streampos end = is.tellg(); cout << end.seekpos() << endl;