How do I make this to work? C++ types are really confusing:
std::wstring wquery = std::wstring(query.begin(), query.end());
//split names
std::vector<WCHAR*> split_names;
std::stringstream ss;
ss.str(names);
std::string name;
while (std::getline(ss, name, ',')) {
split_names.push_back(
(
std::wstring(
name.begin(),
name.end()
)
).c_str()
); //error can't assign const wchar_t* into WCHAR*
}
C++ tries to keep you from mistakes. Here:
std::wstring(name.begin(), name.end())).c_str()
you create a temporary object std::wstring
and get the pointer to the string content. Object will be destroyed right after you leave this block. As a result you will get an invalid pointer.
Don't store pointer to the temporary object into your std::vector<WCHAR*> split_names;
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments