如何使用 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;
}
最佳答案
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);
}
关于C++ 如何使用 find 函数在 char 数组中查找 char?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4060210/