Expression: String Subscript Out of Range
<p>I am getting an error saying that my string subscript is out of range (the error message is the title) whenever I run my code. I expect it to be from using "counter" to calculate total cities and average population. How do I go about fixing this? I have tried other methods to calculate it but none have worked.</p>

<pre><code>void cities( istream&amp; in, ostream&amp; out )
{
    ifstream ("cities.txt");
    string country, city, city2, state, lat, longi;
    int pop;
    int currentPop = 0;
    int smallestPop = 0;
    int largestPop = 0;
    int counter = 0;
    int sum = 0;
    int i = 0;
    int average = 0;
    string largestCity;
    string smallestCity;
    string population;

    readLineOfData(in, country, city, city2, state, pop, lat, longi);
    while(!in.fail())
    {
        counter++;
        output( out, country, city, city2, state, pop, lat, longi );


        readLineOfData(in, country, city, city2, state, pop, lat, longi);

        population[counter] = pop;

        if (pop &lt; smallestPop || smallestPop == 0)
        {
            smallestPop = pop;
            smallestCity = city2;
        }

        if (pop &gt; largestPop || largestPop == 0)
        {
            largestPop = pop;
            largestCity = city2;
        }

        for (int i = 0; i&lt;counter; i++)
        {
            sum += population[i];
            average = sum/counter;
        }
    }

        out &lt;&lt; "Smallest City: " &lt;&lt; smallestCity &lt;&lt; endl;
        out &lt;&lt; "Population: " &lt;&lt; smallestPop &lt;&lt; endl;
        out &lt;&lt; endl;
        out &lt;&lt; "Largest City: " &lt;&lt; largestCity &lt;&lt; endl;
        out &lt;&lt; "Largest Population: " &lt;&lt; largestPop &lt;&lt; endl;
        out &lt;&lt; endl;
        out &lt;&lt; "Total Cities: " &lt;&lt; i &lt;&lt; endl;
        out &lt;&lt; "Average Population: " &lt;&lt; average &lt;&lt; endl;
    return;
}

void readLineOfData( istream&amp; in, string &amp;country,  string &amp;city, string &amp;city2, 
    string &amp;state, int &amp;pop, string &amp;lat, string &amp;longi)
{
    getline( in, country, ',');
    getline( in, city, ',');
    getline( in, city2, ',');
    getline( in, state, ',');
    in &gt;&gt; pop;
    in.ignore( 200, ',' );
    getline( in, lat, ',');
    getline( in, longi, '\n' );

}

void output( ostream&amp; out, string country, string city, string city2,
    string state, int pop, string lat, string longi )
{
}
</code></pre>
