Question: Please .help me with creating .h and .cpp files from the given Program. Correct division of code into .h and .cpp files.Use of #pragma once
Please .help me with creating .h and .cpp files from the given Program. Correct division of code into .h and .cpp files.Use of #pragma once in .h files (or, #ifndef) and include "stdafx.h" in cpp files (or, suppress pch)
#include "stdafx.h" #include
class Log //Class Log definition { private: int logentries; string entry; ofstream fout; public: Log(string fileName) { logentries = 0; fout.open(fileName, ios_base::app);
}
void Entry(string logMessage) { char currenttime[9];
_strtime_s(currenttime); //get current time HH:MM:SS in stime
fout << currenttime << " " << logMessage << endl; //write time and logmessage to file, LogFile.txt
logentries++; //increment the logentries by 1 }
~Log() //Destructor close the file fout object { fout.close(); }
int GetCount() { return logentries; }
};
int main() { string fileName = "C:/MyClass/LogFile.txt"; Log log(fileName); system("pause"); log.Entry("This is my first log file message"); system("pause"); //to pause the entry log.Entry("This is another message"); system("pause"); log.Entry("This is the third and final log file message"); cout << "Number of log entries: #" << log.GetCount() << endl; system("pause"); return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
