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

  • SEARCH
  • Home
  • 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 648105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:47:45+00:00 2026-05-13T21:47:45+00:00

I’m trying to update a random-access binary file using the std::iostream interface with separate

  • 0

I’m trying to update a random-access binary file using the std::iostream interface with separate get/put positions managed via seekg/seekp. Everything works fine with stringstream, but when I create a file descriptor-based stream using Boost.Iostream (specifically boost::iostreams::stream<boost::iostreams::file_descriptor>), the get/put positions are no longer independent.

I gather from the documentation on Modes that what I’m looking for is a “Dual-seekable” stream. The docs show that Mode is a template parameter of stream, “principally for internal use”, but this seems to be (no longer?) correct. Instead, the mode (aka category?) is taken directly from the Device:

template< typename Device,
          typename Tr = ...,
          typename Alloc = ...>
struct stream : detail::stream_base<Device, Tr, Alloc> {
public:
    typedef typename char_type_of<Device>::type  char_type;
    struct category 
        : mode_of<Device>::type,
          closable_tag,
          detail::stream_traits<Device, Tr>::stream_tag
        { };

Primary question: Is there some way to get Dual-seekable behavior from a Device such as file_descriptor (which is tagged Seekable but not Dual-seekable)?

Secondary question: Are there any general guarantees about the independence of seekg/seekp? I gather from web searches that stringstream seems to be independent, but that fstream may not be. However, I can’t find anything authoritative.

  • 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-13T21:47:46+00:00Added an answer on May 13, 2026 at 9:47 pm

    If you construct a bidirectional_seekable boost::iostreams::device it will support two separate get/put positions which can be modified with the help of the iostreams::seek function.

    Roughly, this will look like:

    struct binary_seekable_device 
     : boost::iostreams::device<boost::iostreams::bidirectional_seekable>
    {
        explicit binary_seekable_device(int fd)
          : fd(fd), pos_read(0), pos_write(0) {}
    
        std::streamsize read(char *s, std::streamsize n);
        std::streamsize write(char const *s, std::streamsize n);
        std::streampos seek(boost::iostreams::stream_offset off,
            std::ios::seekdir way, std::ios::openmode which);
    
        int fd; 
        std::size_t pos_read;
        std::size_t pos_write;
    };
    

    You need to implement your stream logic by filling out the three functions (read, write, seek), see the examples and documentation for details. The important point for you is the parameter std::ios::openmode which giving you a clue which of the positions (read, write, or both) you need to update.

    Now you use this device while instantiating an boost::iostreams::stream:

    int fd = open(...);
    boost::iostream::stream<binary_seekable_device> s(fd);
    

    where s is your stream instance you can use to do the require file operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.