C
cdrsir
I have written a program like followings:
#include <iostream.h>
#include <fstream.h>
class cClass
{
ofstream *fout;
char ch;
public:
void pesudoTask() {
cin>>ch;
*fout<<ch<<endl;;
cout<<"have inputed: "<<ch<<endl;;
}
cClass() {
fout = new ofstream("mylog.txt");
*fout<<"program started"<<endl;
}
~cClass() {
*fout<<"program ended"<<endl;
fout->close();
}
};
int main(int argc, char *argv[])
{
cClass o;
while (1) o.pesudoTask();
return 0;
}
in this case, the program can be closed only by either press "Ctrl+c"
or directly click "x" in the shell windows, but the destructor is never
called, the "program ended" is not in the log file, how to do this?
#include <iostream.h>
#include <fstream.h>
class cClass
{
ofstream *fout;
char ch;
public:
void pesudoTask() {
cin>>ch;
*fout<<ch<<endl;;
cout<<"have inputed: "<<ch<<endl;;
}
cClass() {
fout = new ofstream("mylog.txt");
*fout<<"program started"<<endl;
}
~cClass() {
*fout<<"program ended"<<endl;
fout->close();
}
};
int main(int argc, char *argv[])
{
cClass o;
while (1) o.pesudoTask();
return 0;
}
in this case, the program can be closed only by either press "Ctrl+c"
or directly click "x" in the shell windows, but the destructor is never
called, the "program ended" is not in the log file, how to do this?