123456789101112131415161718192021222324252627282930313233343536373839404142
#include <stdexcept> #include <iostream> #include <fstream> #include <string> #include <ctime> using namespace std; string get_local_time() //function to get local time { time_t rawtime; struct tm * timeinfo; timeinfo = localtime(&rawtime); return asctime(timeinfo); } void record_error(string message) //opens or creates an error log { ofstream error_log("error_log.txt",ios_base::app); error_log << get_local_time() << message << endl; } int main() //The purpose of this program is to create an error routine //that can be used with non-console programs. try { throw runtime_error("lets see"); return 0; } catch(exception& e) { record_error(e.what()); return 1; } catch(...) { return 2; }
time ( &rawtime );
Mon Feb 15 13:08:11 2010 lets see
123
timeinfo = localtime(&rawtime); string temp = asctime(timeinfo); return temp.substr(0,temp.size()-1);