title: How can I write some trace in my log file in C++
body: <p>I want to write the date of the execution and the end of execution of a file in my log file.</p>
  
  <p>I can't install anything, just use standard module ( I execute my code in command line with linux ).</p>
  
  <p>I want something like this : 
  <code>[TRACE] 2014-07-24 14:18:50,2014-07-24 14:18:52</code></p>
  
  <p>I have this result for the moment :</p>
  
  <p><code>[TRACE] , Start date of execution : Aug 25 2014 : 10:43:02
  End date of execution : Mon Aug 25 10:43:06 2014</code></p>
  
  <p>here my code :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  void startDateExecution(fstream&amp; file) {
  
      if(fichier)
      {
           file &lt;&lt; "[TRACE]" &lt;&lt; " , " &lt;&lt; "Start date of execution : " &lt;&lt; __DATE__ &lt;&lt; " : " &lt;&lt; __TIME__ &lt;&lt; endl;     
      }
      else
           cerr &lt;&lt; "Unable to open file" &lt;&lt; endl;
  }
  
  void endDateExecution(fstream&amp; file) {
  
          time_t result = time(NULL);
          file &lt;&lt; "End date of execution : " &lt;&lt; asctime(localtime(&amp;result)) &lt;&lt; endl;
  
          file.close();
  }
  
  void displayDate(fstream&amp; file) {
  
       startDateExecution(file);
       endDateExecution(file);         
  }
  
  int main(){
  
        fstream file("trace.log", ios::out | ios::trunc);
        displayDate(file);
        return 0;  
  }
  </code></pre>