Find method in std::wstring

Prabhu picture Prabhu · Dec 27, 2011 · Viewed 16.4k times · Source

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?

Answer

Bo Persson picture Bo Persson · Dec 27, 2011

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

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