Function which takes a string as input and returns the most frequent character
Here’s how I’d write this using the standard library:

#include &lt;algorithm&gt;
#include &lt;unordered_map&gt;
#include &lt;string_view&gt;

char most_frequent_char(std::string_view str) {
    std::unordered_map&lt;char, int&gt; counts;
    for (auto c : str) counts[c] += 1;
    return std::max_element(
        begin(counts), end(counts),
        [](auto a, auto b) {return a.second &lt; b.second;}
    )-&gt;first;
}


But to be honest I’m not happy with manually iterating over the string to counts its characters. In actual code I’d probably abstract away the creation of a frequency table, which would presumably also have a max function. In Python this directly corresponds to the collections.Counter class. If we assume the existence of this utility class (left as an exercise to the reader), the implementation becomes

char most_frequent_char(std::string_view str) {
    return max(freq_table{str}).first;
}


Incidentally, in statistics this property is known as the “mode” of a distribution.