title: c++ how to read and write within a file
body: <p>i want to make a text based rpg game, but ive run into a problem, im fairly "new" to c++, know a few concepts but still learning.
  So what i want to know is; how do i open a file and edit the values in it?
  say i have a file called health, for my characters health and its set to 100. I know you can just subtract the variable by the damage you set the monsters to do, but i dont know how i store the health and edit it, while my program goes along.</p>
  
  <p>ie. this is the farthest i got:</p>
  
  <pre><code>ifstream objectFile("health.txt");
  string health;
  double NoH;
  
  cout &lt;&lt; "welcome" &lt;&lt; endl;
  objectFile &gt;&gt; health &gt;&gt; NoH;
  cout &lt;&lt; health &lt;&lt; ' ' &lt;&lt; NoH - 15;
  </code></pre>
  
  <p>NoH = Number of health. So far all my program does, is read the file, and subtract 15 from 100 because thats the damage the monster do. But how do i make it "take out" the value and subtract 15 from it? then store it back so it's 85, and next time i get hit its 65 for example etc, so it makes it the objective of the game is about surviving, ie avoiding getting hit and stuff. i mean avoiding your hp to reach 0, but also i want to learn how to implement simple text based creatures you can kill, by letting their hp reach 0.
  thanks</p>