在c ++中测试字符串数组的索引?

Lai*_*eme 0 c++ string

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{

    char str[80];
    int i=0;
    cout<<"Enter the String ";
    gets(str);
    for (int j=0;str[j]!='\0';j++)
    if (str[i]=='A'||'E'||'I'||'O'||'U')
    i++;
    cout<<"Number of vowels is: "<<i;



}
Run Code Online (Sandbox Code Playgroud)

这里我是元音字符串中的元素检查元素,有人可以为此建议替代方法吗?我需要计算字符串中的元音数量.

这段代码对我来说很完美,只需要找到替代方法,我不必输入太多"||" 和'a'和'A'不同.

小智 5

if (str[i]=='A'||'E'||'I'||'O'||'U') 
Run Code Online (Sandbox Code Playgroud)

这是错的

应该是这样的:

if(str[i]=='A' || str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
Run Code Online (Sandbox Code Playgroud)

并且还要注意区分大小写