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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:14:21+00:00 2026-05-12T21:14:21+00:00

I am trying to open an output file which I am sure has a

  • 0

I am trying to open an output file which I am sure has a unique name but it fails once in a while. I could not find any information for what reasons the ofstream constructor would fail.

EDIT:
It starts failing at some point of time and after that it continuously fails until I stop the running program which write this file.

EDIT:
once in a while = 22-24 hours

code snippet ( I don’t this would help but still someone asked for it )

ofstream theFile( sLocalFile.c_str(), ios::binary | ios::out );
if ( theFile.fail() ) 
{
    std::string sErr = " failed to open ";
    sErr += sLocalFile;
    log_message( sErr );
    return FILE_OPEN_FAILED;
}
  • 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-12T21:14:21+00:00Added an answer on May 12, 2026 at 9:14 pm

    Too many file handles open? Out of space? Access denied? Intermittent network drive problem? File already exists? File locked? It’s awfully hard to say without more details. Edit: Based on the extra details you gave, it sounds like you might be leaking file handles (opening files and failing to close them and so running out of a per-process file handle limit).

    I assume that you’re familiar with using the exceptions method to control whether iostream failures are communicated as exceptions or as status flags.

    In my experience, the iostream classes give very little details on what went wrong when they fail during an I/O operation. However, because they’re generally implemented using lower-level Standard C and OS API functions, you can often get at the underlying C or OS error code for more details. I’ve had good luck using the following function to do this.

    std::string DescribeIosFailure(const std::ios& stream)
    {
      std::string result;
    
      if (stream.eof()) {
        result = "Unexpected end of file.";
      }
    
    #ifdef WIN32
      // GetLastError() gives more details than errno.
      else if (GetLastError() != 0) {
        result = FormatSystemMessage(GetLastError());
      }
    #endif
    
      else if (errno) {
    #if defined(__unix__)
        // We use strerror_r because it's threadsafe.
        // GNU's strerror_r returns a string and may ignore buffer completely.
        char buffer[255];
        result = std::string(strerror_r(errno, buffer, sizeof(buffer)));
    #else
        result = std::string(strerror(errno));
    #endif
      }
    
      else {
        result = "Unknown file error.";
      }
    
      boost::trim_right(result);  // from Boost String Algorithms library
      return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to output a file in perl. I open the file and
I am trying to log the input/output of expect to an open file. The
I am trying open a very large file in Emacs and it fails to
I'm trying to open a zip file with jython using FileInputStream and ZipInputStream. But
I have written a perl code for processing file 'Output.txt' which has below Content.
I have a csv file which has 3 columns. I am trying to search
I'm trying to open a file for input in Excel with this line :
I'm trying the open a relative path in Ubuntu , but after opening the
I'm trying to open a JSON file from the assets folder with an InputStream
I am trying to build a setup file which will install my vb.net application

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.