#include#include int main() { std::wstring str = L"Hello World"; std::wstring subStr = L"World"; size_t pos = str.find(subStr); if (pos != std::wstring::npos) { std::cout << "Substring found at position " << pos << std::endl; } else { std::cout << "Substring not found" << std::endl; } return 0; }
#includeIn this example, we start searching for the substring "C++" from position 10 within the string "I love programming in C++!". The find method returns the position of the first occurrence of the substring after position 10, which is 22. The wstring find method is part of the C++ standard library and does not require any additional package or library to be installed.#include int main() { std::wstring str = L"I love programming in C++!"; std::wstring subStr = L"C++"; size_t pos = str.find(subStr, 10); // start searching from position 10 if (pos != std::wstring::npos) { std::cout << "Substring found at position " << pos << std::endl; } else { std::cout << "Substring not found" << std::endl; } return 0; }