title: How to open and read a file based on user input c++
body: <p>I have an assignment that wants me to write a program that reads a text file, then outputs a modified version of that file using a version of Ceasar cipher that shifts the characters of the file that the user calls based on the shift amount that they input. For example if my file reads "hi" and they shift it by 1 it should read "ij". But when I run the program it doesnt recognize when I call in1 or out1 and I just get an error message. Can anyone help me figure out what I'm doing wrong or offer any advice on how to move forward? Thank you in advance!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include &lt;cctype&gt;
  using namespace std;
  
  int main()
  {
      //Declare user variables
      int shift, file1chars = 0;
      char filename[25];
      ifstream in1;
      ofstream out1;
  
      do
      {
          in1.clear(); //clear status flags
  
          //Prompt user to enter name of input file and amount of shift
          cout &lt;&lt; "Please enter the name of the input file." &lt;&lt; endl;
          cout &lt;&lt; "Filename: ";
          cin &gt;&gt; filename;
  
          //Open file name
          in1.open(filename);
  
          //Error message if no file
          if (!in1)
              cout &lt;&lt; "That is not a valid file. Try again\n";
  
      } while (!in1);
  
      do
      {
          out1.clear(); //clear status flags
          //prompt user to input out file     
          cout &lt;&lt; "Please enter the name of the output file." &lt;&lt; endl;
          cout &lt;&lt; "Filename: ";
          cin &gt;&gt; filename;
  
          out1.open(filename);
          //Error message if no file
          if (!out1)
              cout &lt;&lt; "That is not a valid file. Try again\n";
      } while (!out1);
  
      //write some code to the input file 
      in1 &gt;&gt; "hi"
  
      //write the integers in a different order to the output file
      out1 &lt;&lt; //idk where to go from here to initiate shift 
  
      //prompt user to enter shift
              cout &lt;&lt; "Please intput the shift amount: ";
      cin &gt;&gt; shift;
      cout &lt;&lt; "Processing complete" &lt;&lt; endl;
  
      //Call file (?)
  
      //Tell user file input is complete and is now printing statistics
      cout &lt;&lt; "\nShifted input file Complete. Now printing statistics " &lt;&lt; endl;
  
      //Show statistics for file
      cout &lt;&lt; "\nStatistics for file: " &lt;&lt; filename &lt;&lt; endl;
      cout &lt;&lt; "------------------------------------------------";
  
      //Show characters in file and stats before shift
      cout &lt;&lt; "\n\nTotal # of characters in file: " &lt;&lt; file1chars &lt;&lt; endl;
      cout &lt;&lt; "Statistics before shift: " &lt;&lt; endl;
  
      //Show file before shift
  
      //Show user stats after shift
      cout &lt;&lt; "\nStatistics after shift: " &lt;&lt; endl;
  
      //File after shift
  
      //Close files
      out1.close();
      in1.close();
      return 0;
  }
  </code></pre>