title: Can a file be opened, read, edited, output into a .txt file and repeated multiple times in a program?
body: <p>So I have had an idea for a program to create a text / console output game. I wanted to make the game solely in the console output using <code>cout</code> but had a different idea.</p>
  
  <p>I understand that a program can open a file, read the information, edit / manipulate the information and output that information into a different file. So something like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  void fileWrite(int Health);  // Prototype for fileWrite
  
  int main()
  {  
    string inFile = "inFile.txt";
    string outFile = "outFile.txt";
    int Health = 100;
  
    ifstream fin;
    ofstream fout;
  
    fin.open("inFile.txt");
    fout.open("outFile.txt);
  
    while (!fin.oef())
    {
     fin &gt;&gt; Health;
     fileWrite(Health);
    }
  
   fin.close();
   fout.close();
   return 0;
  }
  
  void fileWrite(int Health)
  { 
   fout &lt;&lt; setw(10) &lt;&lt; left &lt;&lt; "Health" &lt;&lt; endl;
   fout &lt;&lt; setw(10) &lt;&lt; left &lt;&lt; Health &lt;&lt; endl;
  }
  </code></pre>
  
  <p>So let's say <code>inFile.txt</code> simply has <code>50</code> in the file.
  Like so:</p>
  
  <pre><code>50
  </code></pre>
  
  <p>In theory, the file should be read, <code>health</code> is now set to <code>50</code>, the function <code>fileWrite</code> is called and the output should look like this in the <code>outFile.txt</code> </p>
  
  <pre><code>Health:
  50
  </code></pre>
  
  <p>So what I am wanting to do is make it so that say instead of reading in a file for the health, could I modify <code>Health</code> multiple times during the duration of the program and call <code>fileWrite</code>? Say that health pertains to the main character, and I create a variable named <code>potion</code> and it does +20 towards health, could I open the file. See that the character has <code>50</code> health, output the information into the <code>outFile.txt</code> then take <code>potion</code> which would increase the health to <code>70</code> and reprint the file?</p>
  
  <p>The reason I am trying to find a way to do this is so that the user can use the console for inputting commands, and have the .txt file show the results of the commands.</p>
  
  <p>Can a <code>function</code> be created to handle the printing and be called multiple times in main?</p>