Simple program to detect the number of times a vowel occurs in a string I wrote a simple program to print out any vowels found in a string, as well as the amount of times that vowel occurs. 

Here is my code:

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;map&gt;

void findVowels(std::string&amp; theString, std::map&lt;char,int&gt;&amp; map);
bool vowelCount(char&amp; temp);
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const std::map&lt;char, int&gt;&amp; map);

int main()
{
    bool keepGoing = true;
    while (keepGoing)
    {
        std::cout &lt;&lt; "Enter a string to see how many times vowels were used.\n";
        std::string userInput;
        std::getline(std::cin, userInput);

        std::map&lt;char, int&gt; theMap;
        findVowels(userInput, theMap);

        std::cout &lt;&lt; theMap;
        std::cout &lt;&lt; "\nWould you like to keep going? Please type Y to continue or N to exit.\n";

        char nextAction;
        std::cin &gt;&gt; nextAction;
        if (nextAction == 'N' || nextAction == 'n')
            keepGoing = false;
        else if (nextAction != 'Y' &amp;&amp; nextAction != 'y')
            std::cout &lt;&lt; "Incorrect input. Defaulting to yes.\n";
        std::cin.ignore();
    }
    std::cout &lt;&lt; std::endl;
    system("pause");
    return 0;
}

void findVowels(std::string&amp; theString, std::map&lt;char, int&gt;&amp; theMap)
{
    int stringSize = static_cast&lt;int&gt;(theString.size());
    for (int i = 0; i &lt; stringSize; i++)
    {
        if (vowelCount(theString[i]))
            theMap[theString[i]]++;
    }
}

bool vowelCount(char&amp; temp)
{
    temp = toupper(temp);
    return (temp == 'A' || temp == 'E' || temp == 'I' || temp == 'O' || temp == 'U');
}

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const std::map&lt;char, int&gt;&amp; theMap)
{
    std::map&lt;char, int&gt;::const_iterator iter = theMap.cbegin();
    std::map&lt;char, int&gt;::const_iterator iterEnd = theMap.cend();
    while (iter != iterEnd)
    {
        out &lt;&lt; iter-&gt;first &lt;&lt; " has " &lt;&lt; iter-&gt;second &lt;&lt; " number of occurences.\n";
        iter++;
    }

    return out;
}
I agree mostly with @Yuri, but I feel that regex is an overkill here. Besides, as they say: "Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems". 

Check if a letter is a vowel

I'll begin with this function since it's at the core of your program:

// your code
bool vowelCount(char&amp; temp) 
{
    temp = toupper(temp);
    return (temp == 'A' || temp == 'E' || temp == 'I' || temp == 'O' || temp == 'U');
}


I didn't understand at first why you would pass the argument as a non-const reference. I realized only after that you relied on the inner toupper to store vowels in theMap as capital letters. That's a bad idea! One function should have one purpose and its purpose should be expressed clearly. In this case it assesses if the letter is a vowel, period.

So use a const reference instead or, even better, a copy of the character you take as an argument. A char is 1 byte, so taking it by reference or pointer never is an optimization and can even be a pessimization. 

The other thing I find sub-optimal in your code is the way you test if temp is a vowel. Firstly because there are better, faster ways to find a value in a range,  like binary_search, which is well known as well as available in the standard library (in &lt;algorithm&gt;). Secondly because the vowels' list isn't the same in all languages. For instance, in french, you would need to count 'y', 'à', 'â', 'é', 'è', 'ê', 'î', 'ô', 'ù', 'û', as well. That's why it might be more flexible and readable to keep the list separated from your code. 

So, I would have something like:

bool is_vowel(char c, const std::string&amp; sorted_vowel_list) {
    return std::binary_search(sorted_vowel_list.begin(),
                              sorted_vowel_list.end(),
                              std::toupper(c));
}


A Vowels' map

I'd then count the vowels into a map almost the way you do; I'd only use a range-based loop:

for (auto letter : input_string)
    if (is_vowel(letter))
        ++vowel_map[std::toupper(letter)];


If C++17 is available to you, you can then use "structured bindings" to read the map without referring to iterators:

for (auto [vowel, count] : vowel_map)
    std::cout &lt;&lt; "Vowel: " &lt;&lt; vowel &lt;&lt; " has " &lt;&lt; count &lt;&lt; " occurrences\n";