| re: fout.close()
"Srini" <srinivasa.s@gmail.com> wrote in news:1124694172.825835.285460
@z14g2000cwz.googlegroups.com:
[color=blue]
> It worked fine for me. What compiler are you using? And a bit more
> detail on your code and the error you are getting might help to point
> out the problem.[/color]
VC++6. I agree. Its as simple as it gets. I dont think there are any
typos below. No syntax or compile errors. Runtime error: 'The instruction
at etc etc etc. The memory could not be written.' iostream fstream and
conio.h are included.
This is the basic idea. Note that some things were cut for brevity. There
are three objects, all nested. Middle and Bottom are created in
contructors. At the moment there are only one Top and Middle, but more
could be added later.
using namespace std;
Main()
{
TopObj = new Top;
}
Top::Top()
{
MiddleObj1 = new Middle;
//MiddleObj2 = new Middle;
};
Middle::Middle()
{
BottomObj1 = new Bottom;
//BottomObj2 = new Bottom;
//BottomObj3 = new Bottom;
//BottomObj4 = new Bottom;
//fout does not access the above... test only.
//Intended to put creation variables in a log.
string myname = "George";
ofstream fout;
fout.open("test.txt");
fout << "My name is: " <<myname << endl;
if( fout.is_open() )
fout.close();
}
Bottom::Bottom()
{
x=1;
y=2;
z=3;
}
In actual fact "My name is: George" is written to the file. So I do not
understand what is not being written. |