title: Compiled code doesn't execute file writes
body: <p>I have a class with a <code>run()</code> method that's supposed to write a "header" file, perform some calculations, and write the results of the calculation to a separate file. My problem is that the files never get written. VS code debugger seems to indicate that the <code>.close()</code> calls in the writing methods never get reached. Even when I try to intersperse <code>.flush()</code> methods the file doesn't get any content written, though.</p>
  
  <p>The writing methods call on an inline variable declared in <code>Experiments.h</code>, which is <code>#include</code>d in the file.`Experiments::OUTPUT_DIR= "../results/".</p>
  
  <p>I take it that the problem is the content never gets written because <code>.close()</code> never gets called in the compiled code. But how do I fix this?</p>
  
  <pre><code>// main method in the compiled file
  
  int main(){
      Experiments::Experiment* experiment = new Experiments::UniformRandomAgentGameExperiment();
  
      experiment -&gt; run();
  }
  </code></pre>
  
  <pre><code>// run() method on the experiment class (simplified)
  
  void Experiments::UniformRandomAgentGameExperiment::run(){
  
      write_header();
  
  
      // Start  maintaining output file in memory, then dump at the end of the experiment
  
      std::string output_str;
      output_str.reserve(... a large number I calculate ...);
      output_str+="";
  
  
      // run all the tests
      int games_played=0;
  
      while(games_played&lt;n_games){
  
          // Perform an iteration and accumulate results into output_str.
  
      }
      // I can verify at this point with simple std::cout that output_str has the content it should
      write_experiment(output_str);
  }
  </code></pre>
  
  <pre><code>// write_header() method
  
  void Experiments::UniformRandomAgentGameExperiment::write_header(){
      std::ofstream header(Experiments::OUTPUT_DIR + fileheader+".header",std::ios::out | std::ios::trunc); // &lt;- Debugger indicates this line gets visited
  
      header  &lt;&lt; "Experiment Name: " &lt;&lt; experiment_name &lt;&lt; std::endl
              &lt;&lt; "Experiment Description: " &lt;&lt; description &lt;&lt; std::endl &lt;&lt; std::endl
  
              //... and write some more stuff ... &lt;- Debugger indicates these lines get visited
  
  
      header.close(); // &lt;- Debugger indicates this line is never reached
  }
  </code></pre>
  
  <pre><code>// write_experiment method
  
  void Experiments::UniformRandomAgentGameExperiment::write_experiment(std::string data){
      std::ofstream logfile(Experiments::OUTPUT_DIR + fileheader + ".csv",std::ios::out | std::ios::trunc); // &lt;- Debugger indicates this line gets visited in compiled code
      logfile &lt;&lt; data; // &lt;- Debugger indicates that this line and the next are skipped in compiled code
      logfile.close();
  }
  </code></pre>