[RESOLVED] fstream::seekg 64 bit?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] fstream::seekg 64 bit?

  1. #1
    Join Date
    Sep 2006
    Location
    Sunshine State
    Posts
    517

    [RESOLVED] fstream::seekg 64 bit?

    Hello fellow gurus,

    I am trying to read/write files that can possibly get extremely large.
    However, fstream::seekg/seekp cannot handle 64bit positions.

    How would I go about reading/writing to positions that exceed 4GB?

    The file format itself provides offset information in QWORDS.

    I have thought about jumping from one offset to another until I get where I want to go, but that seems like a hack.
    My idea was as follows:

    Code:
    void SeekFStream(fstream& s, __int64 pos)
    {
        s.seekg(0, ios::beg);
        UINT n4GBSeeks = pos / 0xFFFFFFFF;
        for(UINT i = 0; i < n4GBSeeks; i++)
       {
          s.seekg(0xFFFFFFFF, ios::cur);
       }
    
       // Rest
       s.seekg(pos % 0xFFFFFFFF, ios::cur);
       
    }
    Could that work? Also, can fstream handle >4GB internally?

    Any help would be appreciated.
    Last edited by namezero111111; July 5th, 2007 at 03:45 PM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,427

    Re: fstream::seekg 64 bit?

    Quote Originally Posted by namezero111111
    Hello fellow gurus,

    I am trying to read/write files that can possibly get extremely large.
    However, fstream::seekg/seekp cannot handle 64bit positions.
    Just one thing -- whether you can use 64-bit offsets using fstream is implementation defined by your STL vendor and what they have defined as std::ios::pos_type.

    Since your file system allows files > 4GB, does your OS have dedicated API functions to handle files? If so, then use those functions instead of fstream.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Sep 2006
    Location
    Sunshine State
    Posts
    517

    Re: fstream::seekg 64 bit?

    Thank you for your reply.

    It is my understanding that the Windwos NT/2000/XP series _can_ handle files exceeding 4GB.
    Any suggestions of which functions handle such files?

    I'm sure it's something in the Windows API; any ideas?

  4. #4
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

    Re: fstream::seekg 64 bit?

    Quote Originally Posted by namezero111111
    It is my understanding that the Windwos NT/2000/XP series _can_ handle files exceeding 4GB.
    Any suggestions of which functions handle such files?

    I'm sure it's something in the Windows API; any ideas?
    SetFilePointer() / ReadFile()
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  5. #5
    Join Date
    Sep 2006
    Location
    Sunshine State
    Posts
    517

    Re: fstream::seekg 64 bit?

    Thank you!

    I have found that there are also CreateFile() and CloseHandle(), which are the equivalent to fstream:pen() & fstream::close().

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

    Re: fstream::seekg 64 bit?

    Quote Originally Posted by namezero111111
    Thank you!
    You are welcome.
    Quote Originally Posted by namezero111111
    I have found that there are also CreateFile() and CloseHandle()...
    You got it!
    Quote Originally Posted by namezero111111
    ...which are the equivalent to fstream:pen() & fstream::close().
    Hmmm... Apparently, not very "equivalent"...
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  7. #7
    Join Date
    Sep 2006
    Location
    Sunshine State
    Posts
    517

    Re: fstream::seekg 64 bit?

    Hehe...

    almost equivalent...

    What I meant was that they perform the equivalent tasks on a file handle as the fstream functions on the object : )

    Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center