在c ++中调用函数传递字符串作为参数时出错

Sau*_*gat -4 c++ string character

这是我的代码,在编译时,当我调用isVowel()函数时,它在类型转换中显示错误.你可以检查并告诉错误是什么?

#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
bool isVowel(string a)
{
    if(a == "a" || a =="e" || a =="i" || a =="o" ||a =="u"){
        return true;
    }
    else
        return false;
}

int main()
{
    int T;
    cin>>T;
    for (int i = 0; i < T; i++)
    {
        string s, snew="";
        cin>>s;
        for (int j=0;j<s.length();j++)
        {
            if(isVowel(s[j]))
                continue;
            else
                snew += s[j];
        }
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

dbu*_*ush 5

你的功能是期待一个string但你传递的是char.虽然一个字符串可以容纳一个字符,但它不是一回事.类型需要匹配.

将函数更改为期望a char,并使用字符常量而不是字符串常量进行比较,以便将a char与a 进行比较char.此外,因为如果条件为true或false,您只是返回true或false,只返回比较表达式的结果.

bool isVowel(char a)
{
    return (a == 'a' || a =='e' || a =='i' || a =='o' || a =='u');
}
Run Code Online (Sandbox Code Playgroud)