面试题答案
一键面试#include <iostream>
#include <cstring>
int main() {
const char ch = 'a';
const char str[] = "hello";
bool found = false;
for (size_t i = 0; i < strlen(str); ++i) {
if (str[i] == ch) {
found = true;
break;
}
}
if (found) {
std::cout << "字符 '" << ch << "' 在字符串 '" << str << "' 中" << std::endl;
} else {
std::cout << "字符 '" << ch << "' 不在字符串 '" << str << "' 中" << std::endl;
}
return 0;
}