Note that there are some explanatory texts on larger screens.

plurals
  1. POclr:oldSyntax prevents ofstream
    text
    copied!<p>I have a fairly old unmanaged C++ program that called managed c# code (vs2003) that I need to convert. (the original c# code was written in .NET1.1, and needed to be recompiled, it was compiled into 4.0) While ultimately I need to have the entire thing re-written, I was hoping to get the original code to run a little longer.</p> <p>I have boiled the issue that I am seeing down into this test case:</p> <p>Using VS2010 I created a new project: "Visual C++ | MFC Application"</p> <p>Using the wizard I then created a dialog based application with all of the default settings. After including the following header in the app class,</p> <pre><code>#include &lt;fstream&gt; </code></pre> <p>in the InitInstance of the new App Class I created a file with the following two lines of code:</p> <pre><code>ofstream xmlstream; xmlstream.open("junk.txt"); </code></pre> <p>When the app runs the dialog creates a new file in both Debug and Release mode</p> <p>However, when I try to enable the c# code by changing the project properties|general|common runtime Support flag to Common Runtime support, old syntax (<code>/clr:oldSyntax</code>) I get the following error. In Debug mode the program runs just fine, and creates a file. In Release mode the program crashes executing the line </p> <pre><code>ofstream xmlstream; </code></pre> <p>with the error: </p> <pre>An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.</pre> <p>Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</p> <p>The only other reference to issues with this type of program suggested setting the properties for "C/C++|Code Generation|Enable C++ Exceptions" to <code>/EHa</code> which I have done.</p> <p>I did check for reference to fstream.h instead of fstream (the old style headers no longer exist in 2010, they did in 2003) however I am using the new ones. Unless there is someting wrong with the syntax of declaring a stream object now, I am not sure what is wrong.</p> <p>Is there another switch that I need to set to make this compile correctly, or am I inherently doing something that does not make sense?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload