Finding size of the vector
<p>I'm trying to read in numbers from a file and take the average of all the numbers but i'm unsure how to include the data.resize() and data.reserve() part into my code. I have to use resize and reserve. When I set current_size or max_size to data.size() to 0. Is there another way to find the size of the vector?</p>

<pre><code>//   1) Read in the size of the data to be read (use type size_t)
//   2) Use data.resize() to set the current size of the vector
//   3) Use a for loop to read in the specified number of values,
//      storing them into the vector using a subscript
void readWithResize(vector&lt;int&gt; &amp;data) {
    cout &lt;&lt; "Using resize!" &lt;&lt; endl;

    if (cin){
        size_t current_size;
        current_size = data.size();
        //cin &gt;&gt; current_size;
        cout &lt;&lt; "current_size = " &lt;&lt; current_size &lt;&lt; endl;
        data.resize(current_size);
        for (size_t i = 0; i &lt; current_size; i++){
            cin &gt;&gt; data[i];
            data.push_back(data[i]);
            cout &lt;&lt; data[i] &lt;&lt; " ";
            cout &lt;&lt; current_size &lt;&lt; endl;
        }

    }

//   1) Read in the size of the data to be read (use type size_t)
//   2) Use data.reserve() to set the maximum size of the vector
//   3) Use a for loop to read in the specified number of values,
//      storing them into the vector using data.push_back()
void reserve(vector&lt;int&gt; &amp;data) {

    cout &lt;&lt; "Using reserve!" &lt;&lt; endl;

    if (cin){
        size_t max_size;
        //max_size = 12;

        data.reserve(max_size);
        cout &lt;&lt; "max_size = " &lt;&lt; max_size &lt;&lt; endl;

        for (size_t i = 0; i &lt; max_size; i++){
            cin &gt;&gt; data[i];
            data.push_back(data[i]);
            cout &lt;&lt; data[i] &lt;&lt; " ";
        }

    }
</code></pre>