在 std::wstring 中查找方法

Find method in std::wstring

本文关键字:查找 方法 wstring std      更新时间:2023-10-16

我声明Wstring如下

wstring strID

当我尝试查找出现的子字符串时,如下所示

int index =   strID.find("LABS");

我收到如下错误

error C2664: 'unsigned int std::basic_string<_Elem,_Traits,_Ax>::find(const std::basic_string<_Elem,_Traits,_Ax> &,unsigned int) const' : cannot convert parameter 1 from 'const char [13]' to 'const std::basic_string<_Elem,_Traits,_Ax> &'

你能帮我找到子字符串的出现吗?

搜索 wstring 时,还需要将参数作为宽字符串

int index =   strID.find(L"LABS"); 
                         ^
int index =   strID.find(L"LABS");

编辑:http://msdn.microsoft.com/en-US/library/69ze775t(v=vs.80(.aspx