title: Function for calculating the mean of an array double[] using accumulate
body: <p>It must be the most common function for what everyone has a code snippet somewhere, but I have actually spent no less than 1.5 hour searching for it on SO as well as on other C++ sites and have not found a solution. </p>
  
  <p>I would like to <strong>calculate the mean of a <code>double array[]</code> using a function</strong>. I would like to pass the array to the function as a <strong>reference</strong>. There are millions of examples where the mean is calculated in a main() loop, but what I am looking for is a function what I can put in an external file and use it any time later.</p>
  
  <p>So far, here is my latest version, what gives a compile error:</p>
  
  <pre><code>double mean_array( double array[] )
  {
      int count = sizeof( array ) / sizeof( array[0] );
      double sum = accumulate( array, array + count, 0 );
      return ( double ) sum / count;
  }
  </code></pre>
  
  <p>The compile error is:</p>
  
  <blockquote>
    <p>error C3861: 'accumulate': identifier not found</p>
  </blockquote>
  
  <p>Can you tell me how to fix this function? What does that compile error mean? </p>
  
  <p>If I use <code>std::accumulate</code> (over the already defined <code>using namespace std</code>), then I get the following error:</p>
  
  <pre><code>'accumulate' : is not a member of 'std'
  'accumulate': identifier not found
  </code></pre>
  
  <p>Why is 'accumulate' not a member of 'std'? </p>
  
  <p><em>p.s.: I know I can do 'sum += array[i]' way and not use accumulate, but I would like to understand what is happening here and how can I make my example work.</em></p>