I have a little problem when using lists.
What I have: I am reading lines from a chatbox where new lines of text come now and then. I always fetch the last 20 lines from the box, then i want to compare them to all the lines i have fetched before. If a new line is discovered it is sent to an external function which disassembles the line for further processing. Before I used arrays and vectors, but list seem to be the better way of doing it.
My Idea: I have one list called usedlines which contains all the old allready used lines. The list fetchedLines containes the newest 20lines fetched from the chatbox.
No I simply want to loop trough both of them to find out if fetched lines containes a new line not seen before. After the loop the remains in fetchedlines are handled over to the next function.
Problem: When I loop throug this loop i get a badpointer after a while. Why? Bonus: Does anyone have a better idea to solve this task?
typedef list<string> LISTSTR;
LISTSTR::iterator f;
LISTSTR::iterator u;
LISTSTR fetchedlines;
LISTSTR usedLines;
fetchedlines.insert(fetchedlines.end(), "one");
fetchedlines.push_back("two");
fetchedlines.push_back("three");
fetchedlines.push_back("four");
fetchedlines.push_back("three");
usedLines.push_back("three");
usedLines.push_back("blää");
usedLines.push_back("lumpi");
usedLines.push_back("four");
for (u = usedLines.begin(); u != usedLines.end(); u++)
{
for (f = fetchedlines.begin(); f != fetchedlines.end(); f++)
{
if(*u==*f)
fetchedlines.remove(*f);
}
}
std::set,std::remove_ifandstd::set_intersectionfor a faster solution.