title: How can I change the value of the elements in a vector?
body: <p>I have this code, which reads in input from a file and stores it in a vector. So far, I've gotten it to give me the sum of the values within the vector and give the mean of the values using the sum. </p>
  
  <p>What I'd like to do now is learn how to access the vector again and subtract a value from each element of the vector and then print it out again. For example, once the sum and mean are calculated, I'd like to be able to reprint each value in the terminal minus the mean. Any suggestions/examples?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;fstream&gt;
  #include &lt;cmath&gt;
  
  using namespace std;
  
  int main()
  {
      fstream input;
      input.open("input.txt");
      double d;
      vector&lt;double&gt; v;
      cout &lt;&lt; "The values in the file input.txt are: " &lt;&lt; endl;
      while (input &gt;&gt; d)
      {
          cout &lt;&lt; d &lt;&lt; endl;
          v.push_back(d);
      }
  
  double total = 0.0;
  double mean = 0.0;
  double sub = 0.0;
  for (int i = 0; i &lt; v.size(); i++)
  {
      total += v[i];
      mean = total / v.size();
      sub = v[i] -= mean;
  }
  cout &lt;&lt; "The sum of the values is: " &lt;&lt; total &lt;&lt; endl;
  cout &lt;&lt; "The mean value is: " &lt;&lt; mean &lt;&lt; endl;
  cout &lt;&lt; sub &lt;&lt; endl;
  }
  </code></pre>