2010-12-10 98 views
7

我在做二進制文件處理,在我的算法中,我想知道pos_typeoff_type的實際類型,例如在計算文件大小或尋找給定職位(tellgseekg)。用STL處理大於2 GB的文件大小在C++中

當計算文件的大小我只static_castpos_typeint64_t它似乎工作正常。

seekg怎麼樣?通過int64_t安全嗎?

有沒有一種方法,使pos_typeoff_type是一個int64_t可能使用traits

我想消除可怕的演員,並找到一種符合C++標準的方法。

更新:又見

+0

什麼平臺/版本? – Joe 2010-12-10 01:19:09

+0

平臺獨立的方式:) – Ali 2010-12-10 01:24:27

回答

10

並非所有的編譯器都具有STL實現,並且支持大文件。 2147483647

  • VS2008 - - 2147483647
  • VS2010 - 9223372036854775807
  • MinGW的GCC 4.4.0

    • VS2005:

      例如,下面的程序:在

      #include <fstream> 
      #include <iostream> 
      #include <limits> 
      
      int main() 
      { 
          using namespace std; 
      
          cout << numeric_limits<streamoff>::max() << endl; 
      } 
      

      結果 - 9223372036854775807

    另一方面STLPort已跨平臺大文件支持。