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 6859885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:20:21+00:00 2026-05-27T02:20:21+00:00

In researching forcing files to be written as quickly as possible, I have seen

  • 0

In researching forcing files to be written as quickly as possible, I have seen the following chunk of code in a few places:

_commit(outputFile.rdbuf()->fd());

where outputFile is an std::ofstream object. I am basically doing the following:

std::ofstream outputFile;
outputFile.write((char*)blocks, sizeof(blocks));
outputFile.flush();
_commit(outputFile.fd());
outputFile.close();

blocks is a simply an array of char arrays. What I am doing is writing to an array of char arrays to represent the contents of a binary file, then pushing that array out to the file itself. I need the files to get written as quickly as possible as the medium is somewhat less reliable flash memory and the chance of power outages is unusually high.

When I attempt to compile, I receive the following error on the _commit line of code:

error C2039: 'fd' : is not a member of 'basic_ofstream<char,struct std::char_traits<char> >'

How should I go about getting the file descriptor of outputFile and passing it to _commit?

EDIT: I have changed the above code to reflect using ofstream.fd(), which is supposed to be a public member of ofstream.

  • 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-27T02:20:22+00:00Added an answer on May 27, 2026 at 2:20 am

    Someone should have written this as an answer. They have not so I will steal their glory. 🙂

    The file descriptor is implementation dependent. Some systems might not have one. So the C++ Standard does not define any method to get it from a fstream or filebuf.

    The _commit function in your example is definitely implementation dependent. One big hint is that the name starts with an underscore. A bit of Google shows that _commit only works on Windows.

    To get what you want, you could write your own class derived from streambuf. This customized class would implement IO in the low-level terms that you want to use (Windows, POSIX) and can provide extra functions to return file descriptors or flush data to disk.

    To use the custom class as a stream you would create a ostream and pass it a pointer to your streambuf class.

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

Sidebar

Related Questions

In researching how to convert a NameValueCollection to a querystring, I have come across
I have been researching how to get Cygwin to work under emacs . I
In researching MVC 3 archetectures, one thing I've seen consistently is the concept of
While researching how to create custom compound views in Android, I have come across
Whilst researching data structures for a project a few months back, I came across
I have been researching asynchronous messaging, and I like the way it elegantly deals
I've been researching MVP frameworks for .NET, and Nucleo.NET looks very interesting. I have
After researching all day and night, I have something that is currently working. However,
I have been researching AWS. It seems a little confusing to me. We want
I'm currently researching MongoDb as a possible database option, and I'm having trouble dealing

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.