I have read that boost iostreams supposedly supports 64 bit access to large files semi-portable way. Their FAQ mentions 64 bit offset functions, but there is no examples on how to use them. Has anyone used this library for handling large files? A simple example of opening two files, seeking to their middles, and copying one to the other would be very helpful.
Thanks.
Short answer
Just include
and use the
seekfunction as inwhere
deviceis a file, stream, streambuf or any object convertible toseekable;offsetis a 64-bit offset of typestream_offset;whenceisBOOST_IOS::beg,BOOST_IOS::curorBOOST_IOS::end.The return value of
seekis of typestd::streampos, and it can be converted to astream_offsetusing theposition_to_offsetfunction.Example
Here is an long, tedious and repetitive example, which shows how to open two files, seek to offstets >4GB, and copying data between them.
WARNING: This code will create very large files (several GB). Try this example on an OS/file system which supports sparse files. Linux is ok; I did not test it on other systems, such as Windows.