Compute and print the sum and mean of name and value pairs
Although it might be a bit longer (I haven't bothered to count lines), I think I'd prefer something on this order:

#include &lt;map&gt;
#include &lt;string&gt;
#include &lt;numeric&gt;
#include &lt;iostream&gt;
#include &lt;utility&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;

typedef std::multimap&lt;std::string, float&gt; vtype;
typedef std::pair&lt;std::string, float&gt; ptype;

namespace std { 
std::istream &amp;operator&gt;&gt;(std::istream &amp;is, ptype &amp;v) { 
    return is &gt;&gt; v.first &gt;&gt; v.second;
}
}

float add_second(float a, vtype::value_type b) { 
    return a + b.second;
}

template &lt;class FwdIt&gt;
float average(FwdIt start, FwdIt end) { 
    float total = std::accumulate(start, end, 0.0f, add_second);
    return total / std::distance(start, end);
}

int main() {
    vtype values((std::istream_iterator&lt;ptype&gt;(std::cin)), 
                  std::istream_iterator&lt;ptype&gt;());

    vtype::iterator start, end;

    for (start = values.begin(); start != values.end(); start=end) {
        end = values.upper_bound(start-&gt;first);
        std::cout &lt;&lt; start-&gt;first &lt;&lt; ": " &lt;&lt; average(start, end) &lt;&lt; "\n"; 
    }
    std::cout &lt;&lt; "Overall: " &lt;&lt; average(values.begin(), values.end()) &lt;&lt; "\n";
    return 0;
}


If you preferred, you could use an std::vector instead of an std::multimap. That would require some minor changes to the code (e.g., using std::upper_bound instead of std::multimap::upper_bound, and adding a call to std::sort after reading the data, but would otherwise be pretty similar. It would, however, probably be a bit more efficient (less CPU time and memory).

While I suppose others might disagree, I prefer this for the simple reason that I find it easier to understand. We start by reading in all the data. We then find each run of identical keys, and compute the average for that run and print it out. When we reach the end of the data, we do the same for the overall average.

In fairness, if you were working with huge amounts of data, this probably wouldn't be the best way do do things. It does spend more time walking through the same data than is strictly necessary. At the same time, unless you're going to rewrite the code to overlap reading the data with computing the result, it's unlikely to make much real difference -- almost regardless of how you do the computation, that I/O will almost certainly occupy the vast majority of the overall time.