1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <chrono>
//fonction qui change un point temporel en string
std::string to_string(std::chrono::system_clock::time_point const& tp){
//on récupère une structure time_t
std::time_t tt{ std::chrono::system_clock::to_time_t(tp) };
//on retourne le texte généré par ctime à partir de cette structure
return ctime(&tt);
}
//on crée un point temporel initialisé à "maintenant"
system_clock::time_point beg = system_clock::now();
//on fait semblant de travailler
//std::this_thread::sleep_for(seconds(42));
// on crée un point temporel intialisé à "maintenant"
system_clock::time_point end = system_clock::now();
void startDateExecution(fstream& fichier) {
if(fichier)
{
fichier << "[TRACE] Start date of execution : " << to_string(beg) << endl;
}
else
cerr << "Impossible d'ouvrir le fichier" << endl;
}
void endDateExecution(fstream& fichier) {
time_t result = time(NULL);
fichier << "End date of execution : " << to_string(end) << endl;
fichier.close();
}
void displayDate(fstream& fichier) {
startDateExecution(fichier);
endDateExecution(fichier);
}
int main(){
fstream fichier("trace.log", ios::out | ios::trunc);
displayDate(fichier);
return 0;
} |
Partager