Find method in std::wstring

青春壹個敷衍的年華 提交于 2019-12-10 18:57:24

问题


I have declared Wstring as follows

wstring strID

When I try to find the occurrences sub-string as follows

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

I am getting error like the following

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> &'

Can you please help me to find the occurrences of sub-string?


回答1:


When searching a wstring, you need to have the parameter as a wide string as well

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



回答2:


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

EDIT: http://msdn.microsoft.com/en-us/library/69ze775t(v=vs.80).aspx



来源:https://stackoverflow.com/questions/8644847/find-method-in-stdwstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!