mercredi 23 octobre 2019

Implement a function which calculates how many vowels are present in the string

I wrote the function, but the teacher told me that in the 3 parameter of the count_if function it is necessary to pass the lambda to find out if the letter is vowel. And I can't figure out how to transfer it there. Help please.

unsigned CalculateVowels(const std::string& str)
{
    const std::string& vowels = "aeiouAEIOU";
    unsigned count = std::count_if(str.begin(), str.end(), [](int index) {return str[index] == vowels[index]; })

    return count;
}

Aucun commentaire:

Enregistrer un commentaire