1234567891011121314151617181920212223242526272829303132
#include <iostream> #include <cstring> using namespace std; bool startsWith(const char *s1, const char *s2) { if (s1 == nullptr || s2 == nullptr) return false; return strstr(s1, s2) == s1; } int main(int argc, char *argv[]) { const char *input = "Hello world"; const char *search = "Hello"; if (startsWith(input, search)) { cout << "\nYes"; } else { cout << "\nNo"; } system("pause"); return 0; }