小编oks*_*ovl的帖子

计算字符串中元音的函数

我写了函数。但老师告诉我,在3 个的参数的std::count_if功能,有必要通过拉姆达找出如果这封信是元音。

我不知道如何在那里转移它。

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;
}
Run Code Online (Sandbox Code Playgroud)

c++ algorithm lambda stdstring c++11

4
推荐指数
1
解决办法
111
查看次数

标签 统计

algorithm ×1

c++ ×1

c++11 ×1

lambda ×1

stdstring ×1