Large files in C++

More specifically, wxWidgets and MSVC++ 2010. I found an msdn query that says 2010 is the first version that supports >2Gb file sizes with std::iostream. So that's fine with me. We found a few necessary changes:
  • stat() changes to _stat64()
  • istream::tellg() returns an istream::streampos, not an int.
But what on earth happened here?

// save the beginning position of this line for when we have to back up
istream::streampos begin_line_pos = infile_stream.tellg();
string std_keyword;
infile_stream >> std_keyword;

// bunch of other keyword handling.....
if (keyword == "shape") {
   // Danger! over 2Gb, this turns into negative seek, fails:
   //infile_stream.seekg(begin_line_pos, ios::beg);
   return true;
How does the commented line with the seekg() fail? It should treat begin_line_pos as an offset, which should be 64 bit. It's REALLY LAME if it sees the unsigned streampos and converts it to 32 bits for some reason....
Very strange.
Post a Comment

Popular posts from this blog

Inno Setup custom data directory location

Inno Setup MSVC vcredist without bothering your users