1

我正在尝试读取大于 2GB(约 15GB)的 las 文件,但 ios::fail() 标志在第 345 个字节中变为真。这是下面的代码。

void Foo()
{
  char* filename = "../../../../../CAD/emi/LAS_Data/AOI.las";
  ifstream m_file (filename);

  char c;
  int count = 0;

  if (m_file.is_open())
  {
      while ( m_file.good() )
      {
          m_file.get(c);
          cout << c << endl;
          count++;
      }

      // Check State

      if(m_file.fail())
          cout << "File Error: logical error in i/o operation." << endl;

      if(m_file.eof())
          cout << "Total Bytes Read: " << count << endl;

      m_file.close();
  }
  else
  {
      cout << "File Error: Couldn't open file: " << endl;
  }
}

输出是:

...
File Error: logical error in i/o operation.
Total Bytes Read: 345

我错过了什么?

4

1 回答 1

4

I'm going to guess that you're using Windows. Windows has a quirk that a Control-Z marks the end of a text file, no matter how large the file actually is. The solution is to open the file in Binary mode.

ifstream m_file (filename, std::ios::binary);
于 2013-05-03T16:14:43.923 回答