我的代码中有错误,未声明的标识符

I have an error in my code, undeclared identifier

本文关键字:未声明 标识符 有错误 代码 我的      更新时间:2023-10-16

尝试编译时显示错误

error: use of undeclared identifier 'isVowel'; did you mean 'islower'?

#include <iostream>
#include <cstring>
using namespace std;
int main() {
char word[50];
int num = 0;
cout << "Enter word: ";
cin.getline(word,50);
for(int i=0; word[i]; ++i){
if(isVowel(word[i]))
++num;
}
cout<<"The total number of vowels are "<<num<<endl;

}
bool isVowel(char c){
if(c=='a' || c=='A')
return true;
else if(c=='e' || c=='E')
return true;
else if(c=='i' || c=='I')
return true;
else if(c=='o' || c=='O')
return true;
else if(c=='u' || c=='U')
return true;
return false;
}

在使用函数之前,您需要先对函数进行原型设计。否则编译器不知道它的存在:

bool isVowel(char c); // A prototype of the function you will later call
int main () {
//... Whatever code you're doing....

}
bool isVowel(char c) {
// Actually implement it here.
}