How can I search for files () over 4 GB in Windows?

I work on Windows 7, 64bit and NTFS. I am creating a DLL that should be 32 bits. I have a very simple procedure that I would like to implement in C ++. I am reading a large file using:

unsigned long p; ifstream source(file); streampos pp(p); source.seekg(pp); 

For files over 4 GB, I tried using unsigned long long, but it does not work. What am I doing wrong? I use GNU GCC, would it be useful to use MSVC Express 2008/2010?

Update:

Something seems to be wrong with my GCC. I'm testing your suggestions with MSVC right now, and it looks like it works. MSVC uses _int64 to represent streampos / streamoff objects, I will check GCC later.

+2
source share
3 answers

You may need to use a few relative queries, i.e. use overload with two seekg arguments.

 // Start with seeking from the beginning source.seekg(some_pos, std::ios::beg); // Then seek some more from that position source.seekg(some_offset, std::ios::cur); 
+1
source

If you are running on a 32-bit system, you are probably out of luck doing it in a simple way, although the thread library can use the 64-bit word for its pos_type . However, this may work to use relative queries. Since all requests return a pos_type , which supposedly indicates the current position, this may still not work too well.

I think it's just me, but I have never looked for too much. Of course, having realized this mess, I also know that searching inevitably kills performance and that it really only works when using files opened in std::ios_base::binary mode that do not use any code conversion.

+2
source

I believe that you have to use your own Win32 calls for this, for example SetFilePointerEx http://msdn.microsoft.com/en-us/library/aa365542(VS.85).aspx

+1
source

All Articles