-1

how can we get the end date of execution of the file. Actually,I have created a file who write in a file.

I would like to write in this file, the end date of execution, that's is possible ?

My file :

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

void writeOn(fstream& file) {

    if(file)
    {
        string name = "Peter";
        string nickname = "Shanks";

        file << "Hi, " << name << endl;
        file << __DATE__ << ":" << __TIME__ << endl;
    }
    else
        cerr << "Unable to open file" << endl;

int main() {
    fstream file("trace.log", ios::out | ios::trunc);
    writeOn(file);
    return 0;  
}
shanks
  • 9
  • 1
  • 6
  • Your question is very unclear. Perhaps you could edit it to contain a single, simple question? –  Aug 06 '14 at 11:59
  • @Poldie : I wannt to write the end date of the execution of the file ... what's unclear for you, tell me please and I will try to explain. – shanks Aug 06 '14 at 12:14
  • "how can we get the end date of execution of the file." looks like a question, but no question mark. Is this the same as the next question? If so, remove the first one as it's unclear. Writing a date to a file sounds different to "getting" the "end date of execution" of a file, which sounds like a property of the file itself, rather than the contents. There's some bad grammar/spelling in there too, which can be ignored/clarified once the basic question makes sense. –  Aug 06 '14 at 12:15

1 Answers1

0

You can use following at start of execution and at end of execution

#include <ctime>

//.....

std::time_t result = std::time(NULL);
file << std::asctime(std::localtime(&result)) << std::endl ;

Ref : Here

P0W
  • 46,614
  • 9
  • 72
  • 119
  • that would be the compilation date and time. – idefixs Aug 06 '14 at 11:45
  • @POW : It's normal that I have the day only for the end date ?, that's what I have : Aug 6 2014:14:09:11/nWed Aug 6 14:09:15 2014, and could you comment your response please ( you are more strong than me ) – shanks Aug 06 '14 at 12:12