In my project, i generate a logfile (text file) to write the intermediate results.
i use statement as a global declaration of an object of ofstream.
ofstream outLog;
then in the class constructor i use
outLog.open(outLogFname.c_str(),ios::app);
and in the destructor i close the file.
outLog.close();
I use outLog<<"....."; statement to write the log within all class functions.
Unfortunately it create the particular class but file remains empty.
Due to the long code i can not past the whole implementation.
I need your guidance that what is best way to declare/open a file which should be available for all class functions rather than opening and closing a file in each function.
you seem to be having a stream object in the class and using the object in each function. so implementation looks fine, just that there is nothing coming in the file. you have to find the reason for that. Is this the problem or something else?
Just keep in mind, until you close your file you will not see anything in the file.