I need to split LPWSTR with multiple delimiters & return array of LPWSTR in c++. How to do it? I tried to do from the following question: How to split char pointer with multiple delimiters & return array of char pointers in c++?
But it prints ?? for each wstring. What's wrong with it?
can I do it as I tried follow? If so what's the mistake I made? If not how to do it?
std::vector<wstring> splitManyW(const wstring &original, const wstring &delimiters)
{
std::wstringstream stream(original);
std::wstring line;
vector <wstring> wordVector;
while (std::getline(stream, line))
{
std::size_t prev = 0, pos;
while ((pos = line.find_first_of(delimiters, prev)) != std::wstring::npos)
{
if (pos > prev)
{
wstring toPush = line.substr(prev, pos-prev);
//wstring toPushW = toWide(toPush);
wordVector.push_back(toPush);
}
prev = pos + 1;
}
if (prev < line.length())
{
wstring toPush = line.substr(prev, std::wstring::npos);
//wstring toPushW = toWide(toPush);
wordVector.push_back(toPush);
}
}
for (int i = 0; i< wordVector.size(); i++)
{
//cout << wordVector[i] << endl;
wprintf(L"Event message string: %s\n", wordVector[i]);
}
return wordVector;
}
int main()
{
wstring original = L"This:is\nmy:tst?why I hate";
wstring separators = L":? \n";
vector<wstring> results = splitManyW(original, separators);
getchar();
}