4

Possible Duplicate:
how to check string start in C++

I need to check if wstring begins with a particular string.

const wstring str = "Hello World";
wstring temp="Hello ";

How I can check str begins with temp or not?

4

1 回答 1

11

开始使用宽字面量;然后轻而易举:

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 */ }
于 2012-07-24T22:32:31.527 回答