Looking for a file larger than 4 GB in C ++?

I use the MS Visual Studio 2012 compiler, and I built it in x64 release mode.

Using ifstream, I can read files larger than 4 GB. The problem is that I cannot find a position in the middle of a 10 GB file.

When I use seekg like this is.seekg (5368709120, is.beg); , then is.tellg(); returns -1, which means the search did not work. I am sure that the file exists and the position 5368709120 exists. It works fine if I use: is.seekg (100, is.beg); eg.

Using multiple requests is not an option, as files can receive up to 300 GB (and using many requests will be slow).

My question is: how can I look for the correct work on a 10 GB file without using multiple queries?

+4
source share
1 answer

how can I look for work correctly in a 10 GB file without using multiple queries?

Forgetting the rest of your post, the answer to this question (on Windows) is very simple: use _fseeki64 . I don’t see the problem of switching to a lower level API when working with huge files - are you likely to make large chunks to read / write anyway? You can easily use fread and fwrite for this.

If you insist on STL, the Microsoft implementation will not work. I heard that STLPort handles a large file search, so you can go for it. This is a pretty hard approach, although I would stick with the base fseek .

+5
source

All Articles