#include#include int main() { std::string str1 = "Hello"; std::string str2 = "World"; std::string result = str1 + " " + str2; std::cout << result << std::endl; return 0; }
#includeIn this example, we create a string variable `str` containing a sentence. We then create another string variable `sub_str` containing a substring we want to search for. We then use the `find` method of the string class to determine the position of the first occurrence of the substring within the larger string. If the substring is found, we print the position where it was found, otherwise we print a message indicating it was not found. The package/library used in these examples is the C++ Standard Library, which is included with most C++ compilers and IDEs.#include int main() { std::string str = "The quick brown fox jumps over the lazy dog"; std::string sub_str = "fox"; size_t pos = str.find(sub_str); if (pos != std::string::npos) { std::cout << "Substring found at position " << pos << std::endl; } else { std::cout << "Substring not found" << std::endl; } return 0; }