title: Output file keeps being created even when input file doesn't exist? ****EDIT****
body: <p>I am trying to write a program that moves the first line of a file into a new file. My goal is for the new file to not be created if the input file does not exist. I get it to read <code>.good()</code> so I get the message that the input failed. However, I cannot get the new file to not be created.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>int main()
  {
          fstream inFile;
          fstream outFile;;
          string fileName("");
          string destName("");
  
          cout &lt;&lt; "Please enter file name: ";
          cin &gt;&gt; fileName;
          cout &lt;&lt; endl;
  
          cout &lt;&lt; "Please enter file name of destination: ";
          cin &gt;&gt; destName;
          cout &lt;&lt; endl;
  
          inFile.open(fileName, ios::in);
          outFile.open(destName, ios::out);
  
          getline(inFile, fileName);
  
          if (inFile.good() != true) { 
                  cout &lt;&lt; "?Unable to input file!\n" &lt;&lt; endl; 
                  return 0;
          }   
  
          else {
                  outFile &lt;&lt; fileName &lt;&lt; endl;
                  return 0;
          }   
  
          if (outFile.good() == true) {
  
                  cout &lt;&lt; "?File '" &lt;&lt; destName &lt;&lt; "' already exists!\n" &lt;&lt; endl;
                  return 0;
          }   
  
          inFile.close();
          outFile.close();
  
          return 0;
  }
  </code></pre>
  
  <p>Can anybody help? </p>
  
  <p>Thank you in advance.</p>
  
  <p>Thank you for the help from earlier,</p>
  
  <p>*****EDIT***** </p>
  
  <p>I am curious now though. If the output file already exists, I want to make an error statement saying so. However, if the file exists or doesn't exist, I am still getting an error. I tried to move the outFile.open to the bottom so that the file is created before the check but it still says it already exists? </p>
  
  <pre><code>int main()
  
  {
          fstream inFile;
          fstream outFile;;
          string fileName("");
          string destName("");
  
          cout &lt;&lt; "Please enter file name: ";
          cin &gt;&gt; fileName;
          cout &lt;&lt; endl;
  
          inFile.open(fileName, ios::in);
  
          getline(inFile, fileName);
  
          if (inFile.good() != true) { 
                  cout &lt;&lt; "?Unable to input file!\n" &lt;&lt; endl; 
                  return 0;
          }   
  
          cout &lt;&lt; "Please enter file name of destination: ";
          cin &gt;&gt; destName;
          cout &lt;&lt; endl;
  
  
          if (outFile.good() == true) {
  
                  cout &lt;&lt; "?File '" &lt;&lt; destName &lt;&lt; "' already exists!\n" &lt;&lt; endl;
                  return 0;
          }   
  
          outFile.open(destName, ios::out);    
          outFile &lt;&lt; fileName &lt;&lt; endl;
  
  
          inFile.close();
          outFile.close();
  
          return 0;
  }
  </code></pre>