I have come across what is, I think, a bug with Visual C++ running under Windows NT4. Compiler : Visual C++ 6.0 SP5. Operating System : Windows NT4 Service Pack 6a. My code has the following structure: #include statements using namespace std; int main() { A lot of computations, input & output operations using streams.............. CString file = "c:\\results.txt"; int history = 20; const int calcPeriodHalfhours = 6; ofstream outFile1; outFile1.open(file); for (calcPeriod = 1; calcPeriod < calcPeriodHalfhours + 1; calcPeriod++) { outFile1 << history + calcPeriod; // this is the line that causes the grief. outFile1 << endl; } outFile1.close(); outFile1.clear(); return 0; } If I run the Debug Version of this code, everything is works, and the program exits normally. Under the Release Version (compiled with /O2 /Ob0), the code runs to the end, producing the correct output, but then comes up with the Application Error "The instruction at "0x00418698" referenced memory at "0x0000000b". The memory could not be "read". This is an unhandled Access Violation. Memory is not released to the operating system. If I disable the optimisations (/Od), the code runs fine. If I change the line: outFile1 << history + calcPeriod; // this is the line that causes the grief. to outFile1 << history; // this is the line that causes the grief. or to outFile1 << calcPeriod; // this is the line that causes the grief. the code runs fine as Release Version (compiled with /O2 /Ob0). If I declare the "ofstream outFile1" in the global space instead of in the function space, the code runs fine as Release Version (compiled with /O2 /Ob0). If I run the original code as Release Version (compiled with /O2 /Ob0) under Windows 2000 SP1, the code runs fine. Has anyone come across somethding like this problem before? Please let me know. Thank-you Doug Murray Doug