用于计算字符串中的元音的功能

问题描述 投票:2回答:1

我写了函数,但是老师告诉我,在std::count_if函数的第3个参数中,必须传递来确定字母是否为元音我不知道如何在那里转移它。

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; }

我编写了函数,但是老师告诉我,在std :: count_if函数的第三个参数中,有必要传递lambda来确定字母是否为元音。我不知道如何...
c++ algorithm lambda count stdstring
1个回答
6
投票
您的lambda函数错误。
© www.soinside.com 2019 - 2024. All rights reserved.