#include#include int main() { std::string str = "Hello, world!"; std::size_t found = str.find("world"); // returns 7 if (found != std::string::npos) { std::cout << "Substring found at position " << found << std::endl; } else { std::cout << "Substring not found" << std::endl; } return 0; }
#include#include int main() { std::string str = "She sells seashells by the seashore"; std::size_t found = str.find("sea"); // returns 10 while (found != std::string::npos) { std::cout << "Substring found at position " << found << std::endl; found = str.find("sea", found + 1); } return 0; }
Substring found at position 10 Substring found at position 27 Substring found at position 35The `std::string find` function belongs to the C++ standard library, so it does not require any additional external library packages.