title: Why isn't my rename file working?
body: <p>I am having trouble with renaming a file.  I'm attempting to delete several lines of an existing file, and replace it with the new one.</p>
  
  <pre><code>string line;   
  ifstream myfile(filename);  
  ofstream outfile;  
  outfile.open(filename.append(".new"));  
  
  if(myfile.is_open()) {
      //loop here that runs through code and calles
      //outfile &lt;&lt; line; repeatedly
  }
  
  int test = rename(filename.append(".new").c_str(),filename.c_str());
  if (test == 0) cout &lt;&lt; "Success";
  else cout &lt;&lt; "Failure";
  </code></pre>
  
  <p>From what I have seen online, I would expect this to create the new document, fill it, and then replace the original with the updated one.</p>
  
  <p>Does anyone see where I have gone wrong?</p>