std::wstring str = L"Hello World!"; str.replace(6, 1, L",");
std::wstring str = L"The quick brown fox jumps over the lazy dog"; std::wstring newStr = L"swift"; str.replace(4, 5, newStr);
std::wstring str = L"Happy birthday to you, happy birthday to you"; std::wstring toReplace = L"birthday"; std::wstring replacement = L"anniversary"; size_t pos = 0; while ((pos = str.find(toReplace, pos)) != std::wstring::npos) { str.replace(pos, toReplace.length(), replacement); pos += replacement.length(); }In this example, all occurrences of the substring "birthday" in the wstring are replaced with "anniversary", resulting in the wstring "Happy anniversary to you, happy anniversary to you". Overall, the std::wstring replace function is a useful tool for modifying strings in C++.