Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 628407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:38:02+00:00 2026-05-13T19:38:02+00:00

I have read that boost iostreams supposedly supports 64 bit access to large files

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:38:02+00:00Added an answer on May 13, 2026 at 7:38 pm

    Short answer

    Just include

    #include <boost/iostreams/seek.hpp>
    

    and use the seek function as in

    boost::iostreams::seek(device, offset, whence);
    

    where

    • device is a file, stream, streambuf or any object convertible to seekable;
    • offset is a 64-bit offset of type stream_offset;
    • whence is BOOST_IOS::beg, BOOST_IOS::cur or BOOST_IOS::end.

    The return value of seek is of type std::streampos, and it can be converted to a stream_offset using the position_to_offset function.

    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.

    /*
     * WARNING: This creates very large files (several GB)
     * unless your OS/file system supports sparse files.
     */
    #include <boost/iostreams/device/file.hpp>
    #include <boost/iostreams/positioning.hpp>
    #include <cstring>
    #include <iostream>
    
    using boost::iostreams::file_sink;
    using boost::iostreams::file_source;
    using boost::iostreams::position_to_offset;
    using boost::iostreams::seek;
    using boost::iostreams::stream_offset;
    
    static const stream_offset GB = 1000*1000*1000;
    
    void setup()
    {
        file_sink out("file1", BOOST_IOS::binary);
        const char *greetings[] = {"Hello", "Boost", "World"};
        for (int i = 0; i < 3; i++) {
            out.write(greetings[i], 5);
            seek(out, 7*GB, BOOST_IOS::cur);
        }
    }
    
    void copy_file1_to_file2()
    {
        file_source in("file1", BOOST_IOS::binary);
        file_sink out("file2", BOOST_IOS::binary);
        stream_offset off;
    
        off = position_to_offset(seek(in, -5, BOOST_IOS::end));
        std::cout << "in: seek " << off << std::endl;
    
        for (int i = 0; i < 3; i++) {
            char buf[6];
            std::memset(buf, '\0', sizeof buf);
    
            std::streamsize nr = in.read(buf, 5);
            std::streamsize nw = out.write(buf, 5);
            std::cout << "read: \"" << buf << "\"(" << nr << "), "
                      << "written: (" << nw << ")" << std::endl;
    
            off = position_to_offset(seek(in, -(7*GB + 10), BOOST_IOS::cur));
            std::cout << "in: seek " << off << std::endl;
            off = position_to_offset(seek(out, 7*GB, BOOST_IOS::cur));
            std::cout << "out: seek " << off << std::endl;
        }
    }
    
    int main()
    {
        setup();
        copy_file1_to_file2();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once a Boost library (I have read that ten Boost libs are considered to
I have the following question on boost::iostreams . If someone is familiar with writing
I'm new to boost and its iostreams package and finding the documentation a bit
I seem to be having an issue with boost::interprocess::file_lock I have process 1 that
I have searched the web and read through the Boost documentation about shared_ptr .
I have a database that is read-only in nature. So it seems to make
so i use BOOST.EXTENTION to load modules. I have a special file that describes
I have some socket connection code that makes use of boost::asio which reads from
I read at multiple places that Boost.Signals is not threadsafe but I haven't found
I have read about when you are making a multicolumn index that the order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.