title: C++ Remove function not working
body: <p>Trying to edit some info in a text file. I change what I need, leave what I don't, and the put it in a temporary text file. Once the program is done, I want to delete the old text file and rename the temporary one the name of the old one.</p>
  
  <p>Remove does not seem to be working in this case...</p>
  
  <pre><code>else if (input == 2){
          cout&lt;&lt;"Work?"&lt;&lt;endl;
          string checkUser = username; //set checkUser var equal to username var
          string checkPass = password;
          ofstream outfile("pleasework.txt");
          ifstream infile("userinfo.txt"); //CREATING IFSTREAM
          string u, p, b;
          cout&lt;&lt;checkUser;
          while(infile&gt;&gt;u&gt;&gt;p&gt;&gt;b)
              {
             //cout&lt;&lt;"PLeae"&lt;&lt;endl;
             cout&lt;&lt;u&lt;&lt;' '&lt;&lt;p&lt;&lt;' '&lt;&lt;b&lt;&lt;endl;
              if(checkUser == u){
              cout&lt;&lt;"Current Balance: "&lt;&lt;balance&lt;&lt;endl;
              cout&lt;&lt;"Enter new balance: ";
              int newBalance;
              cin&gt;&gt;newBalance;
              outfile&lt;&lt;checkUser&lt;&lt;' '&lt;&lt;checkPass&lt;&lt;' '&lt;&lt;newBalance&lt;&lt;endl;
              //outfile&lt;&lt;username&lt;&lt;' '&lt;&lt;password&lt;&lt;' '&lt;&lt;newBalance&lt;&lt;endl;
              }else
              {
              outfile&lt;&lt;u&lt;&lt;' '&lt;&lt;p&lt;&lt;' '&lt;&lt;b&lt;&lt;endl;
              }//end else
          }//end while
              infile.close();
              cout&lt;&lt;"Infile closed"&lt;&lt;endl;
              outfile.close();
              cout&lt;&lt;"Outfile closed"&lt;&lt;endl;
              remove("userinfo.txt");
              cout&lt;&lt;"Were past remove!"&lt;&lt;endl;
              int result;
              char oldname[] = "pleasework.txt";
              char newname[] = "userinfo.txt";
              rename(oldname, newname);
              //result = rename (oldname, newname);
              result = (remove("userinfo.txt"));
              if(result == 0)
                  puts("file was renamed");
              else
                  perror("Error");
              return 0;
  
      }
  </code></pre>
  
  <p>I keep getting "Error: File Exists!"
  Have I missed closing the file somewhere?</p>