如何使用C++检查<wstring>是否以某个字符串开头

JCh*_*han 3 c++ visual-c++

可能重复:
如何在C++中检查字符串start

我需要检查wstring是否以特定字符串开头.

const wstring str = "Hello World";
wstring temp="Hello ";
Run Code Online (Sandbox Code Playgroud)

我怎么检查str开始temp与否?

Ker*_* SB 10

为初学者使用宽文字; 然后这是一件轻而易举的事:

std::wstring const str = L"Hello World";

// one method:
if (str.substr(0, 6) == L"Hello ") { /* yay */ }

// another method, better:
if (str.find(L"Hello ") == 0) { /* hooray */ }
Run Code Online (Sandbox Code Playgroud)