c++ - Cannot convert from stringw to string / char -


i have been trying convert irr::stringw (irrlicht game engine core string) can explode string @ delimiter create array / list.

however, cannot convert stringw, not compatible normal functions.

so, split stringw list have following:

vector<stringw> split(stringw str, char delimiter){     vector<stringw> internal;     std::string tok;     std::string std_s(str.c_str(), str.size());      while (getline(std_s, tok, delimiter)) {         internal.push_back(tok);     }     return internal; } 

however errors here are: str.c_str() says no instance of constructor "std::basic::string matches argument list. argument types (const wchar_t*, irr:u32)

on getline method error: no instance of overloaded function "getline" matches argument list. argument types are: (std::string, std::string, char).

i have been trying hours number of ways split stringw @ delimiter of ";" (semi colon) nothing working. advice?

there 2 main issues here, first stringw string of wchar_t characters. need use std::wstring facilities avoid having convert wchar_t to/from char.

we need note std::getline requires type derived std::basic_istream it's first argument. can therefore modify code follows:

vector<stringw> split( stringw str, wchar_t delimiter ) {     vector<stringw> internal;     std::wstring tok;     std::wistringstream std_s( str.c_str() );      while( getline(std_s, tok, delimiter) ) {         internal.push_back(tok);     }     return internal; } 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -