#include#include int main() { std::string s = "The quick brown fox jumps over the lazy dog."; std::string substr = "brown"; bool exists = s.find(substr) != std::string::npos; if (exists) { std::cout << "Substring exists!" << std::endl; } else { std::cout << "Substring does not exist." << std::endl; } return 0; }
#includeIn this example, we use the same `find()` function to check if the substring "apple" exists within the string "This is a test." Since "apple" is not a substring of the original string, `exists` is set to false, and the program prints a message indicating that the substring does not exist. The `find()` function is part of the standard library in C++ and does not require any additional packages or libraries.#include int main() { std::string s = "This is a test."; std::string substr = "apple"; bool exists = s.find(substr) != std::string::npos; if (exists) { std::cout << "Substring exists!" << std::endl; } else { std::cout << "Substring does not exist." << std::endl; } return 0; }