Why ofstream would fail to open the file in C++? Reasons?
<p>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.</p>

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

<p><strong>EDIT:</strong>
once in a while = 22-24 hours </p>

<p>code snippet ( I don't this would help but still someone asked for it )</p>

<pre><code>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;
}
</code></pre>
