title: How to restore stdout after using freopen
body: <p>I try to redirect output in my c++ program from stdout with the following:</p>
  
  <pre><code> freopen(cmd.c_str(),"w",stdout);    
  </code></pre>
  
  <p>Then I call system to execute cmd. I have also tried forking and then calling execvp. Either way, when program control returns to my program, things written to stdout are no longer showing. How can normal behavior be restored?</p>