如何使用find函数在char数组中查找char?如果我只是为了循环元音然后我可以得到答案但我被要求使用std :: find ..谢谢.
bool IsVowel (char c) {
char vowel[] = {'a', 'e', 'i', 'o', 'u'};
bool rtn = std::find(vowel, vowel + 5, c);
std::cout << " Trace : " << c << " " << rtn << endl;
return rtn;
}
Run Code Online (Sandbox Code Playgroud)
bool IsVowel (char c) {
char vowel[] = {'a', 'e', 'i', 'o', 'u'};
char* end = vowel + sizeof(vowel) / sizeof(vowel[0]);
char* position = std::find(vowel, end, c);
return (position != end);
}
Run Code Online (Sandbox Code Playgroud)