#include#include int main() { std::wstring str = L"Hello, world!"; wchar_t delimiter = L','; size_t pos = str.rfind(delimiter); // search for the last occurrence of delimiter if (pos != std::wstring::npos) // if found { std::wstring sub = str.substr(pos + 1); // get the substring after delimiter std::wcout << sub << std::endl; // output: " world!" } return 0; }
#includeIn this example, we use `wstring::rfind()` to find the last occurrence of the substring "world" in the wide string `str`. If found, we output the position of the last character of the found substring. Package library: This function is a member of the C++ Standard Library, so it is available in any C++ compiler that supports the standard library. Therefore, no additional package library is required.#include int main() { std::wstring str = L"Hello, world!"; std::wstring sub = L"world"; size_t pos = str.rfind(sub); // search for the last occurrence of sub if (pos != std::wstring::npos) // if found { std::wcout << "Found at position " << pos << std::endl; // output: "Found at position 7" } return 0; }