2010-12-10 102 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已跨平台大文件支持。