I have a stream of words that give me a word in each run of the loop as std::string
. But ideally this should be std::wstring
. So after I obtain the string I convert it to std::wstring
. This I input into a std:wstringstream
. Finally, after all words from the stream are processed,and then I convert the std:wstringstream
into a std::wstring
, and then search for the required term (originally a std::wstring
) in it. This is my code:
while (stream)
{
std::string word = stream->getWord();
boost::trim(word);
std::wstring longWord(word.length(), L' '); // Make room for characters
std::copy(word.begin(), word.end(), longWord.begin());
fMyWideCharStream << longWord;
stream->next();
}
std::wstring fContentString = fMyWideCharStream.str();
size_t nPos = fContentString.find(fSearchString, 0); //fSearchString is std::wstring
while(nPos != std::wstring::npos)
{
qDebug() << "Pos: " << nPos << endl;
nPos = fContentString.find(fSearchString, nPos+1);
}
I have this string: Passive Aggressive Dealing With Passive Aggression, Lost Happiness & Disconnection Copyright © 2014, where the © is a wide character. As std::string
it takes up two positions. As std::wstring
it takes 1, which is what I want. However, on trying fSearchString
with a value of L"2014"
, I am still getting a value of 96, whereas it should be 95 since this string is now std::wstring
.
Any idea what I should do to fix this?