I save messages in string and I need to make filter function that finds user specified word in those messages. I've split each message by '\n'
so the example of one chat would be:
user1:Hey, man\nuser2:Hey\nuser1:What's up?\nuser2:Nothing, wbu?\n
etc.
Now user could ask to search for word up
and I've implemented a search like this:
for (auto it = msg.cbegin(); (it = std::find(it, msg.cend(), str)) != msg.cend(); it++)
and I could put that string into stringstream and use getline
to \n
, but how do I go backwards to previous \n
so I can get full message? Also, what about first message, cause it doesn't start with \n
?