fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. template <class E, class T = std::char_traits<E>, unsigned N = 0>
  5. std::basic_string<E, T> convertLiteral(char const(& lit)[N])
  6. { return std::basic_string<E, T>(lit, lit+N); }
  7.  
  8. int main()
  9. {
  10. std::wstring wfoo(L"Oh my foo!");
  11.  
  12. auto tag = convertLiteral<wchar_t>("foo");
  13. auto pos = wfoo.find(tag);
  14. if (pos != std::wstring::npos)
  15. wfoo.replace(pos, tag.length(), L"bar");
  16. else
  17. std::wcout << "meh!\n";
  18. std::wcout << wfoo;
  19. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
meh!
Oh my foo!