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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:37:04+00:00 2026-05-26T18:37:04+00:00

I have a C++ program that is writing to a file on Windows 7.

  • 0

I have a C++ program that is writing to a file on Windows 7. When I call f.flush() the NTFS file does not get bigger. Is there any way to force the file to get flushed?

  • 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-26T18:37:04+00:00Added an answer on May 26, 2026 at 6:37 pm

    You can look here:
    How do I get the file HANDLE from the fopen FILE structure?
    the code looks like this:

     FlushFileBuffers((HANDLE) _fileno(_file));
    

    do not forget call fflush(file), before call FlusFileBuffers.

    For std::fstream and gnu stl, I checked it on my linux box, have no windows at home,
    but should work with mingw, may be need some modifications:

    #include <cstdio>
    #include <cstdlib>
    #include <cassert>
    #include <fstream>
    #include <ext/stdio_filebuf.h>
    
    
    int main(int argc, char *argv[])
    {
        assert(argc == 2);
        std::ifstream f(argv[1]);
        assert(!!f);
    /*
        //cin, cout etc
        __gnu_cxx::stdio_filebuf<char> *stdio_buf = dynamic_cast<__gnu_cxx::stdio_filebuf<char> *>(f.rdbuf());
        if (stdio_buf != 0) {
            printf("your fd is %d\n", stdio_buf->fd());
            return EXIT_SUCCESS;
        }
    */
        std::basic_filebuf<char> *file_buf = dynamic_cast<std::basic_filebuf<char> *>(f.rdbuf());
        if (file_buf != 0) {
            struct to_get_protected_member : public std::basic_filebuf<char> {
                int fd() { return _M_file.fd(); }
            };
            printf("your fd is %d\n", static_cast<to_get_protected_member *>(file_buf)->fd());
        }
        printf("what is going on?\n");
        return EXIT_FAILURE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On Windows 7, I have a command-line program that fails due to file write permission
Im writing a program that should read input via stdin, so I have the
I have Virtual PC 2007. I am writing a C# program that will run
I have a table that contains log entries for a program I'm writing. I'm
I have a program that creates a Windows user account using the NetUserAdd() API
I'm writing a Java program that will be used on both Windows and Mac.
I have been writing a small java application (my first!), that does only a
I'm writing a program that uses File I/O to traverse through a directory given
I am writing a java program that needs a file open dialog. The file
I am writing a program that will open an image file, but strange thing

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.