I have a little problem when using lists.
What I have: I read lines from the chat where new lines of text appear. I always extract the last 20 lines from the window, then I want to compare them with all the lines that I have already used. If a new line is found, it is sent to an external function that parses the line for further processing. I used to use arrays and vectors, but the list was apparently the best way to do this.
My idea: I have one list called usedlines that contains all the old already used lines. The fetchedLines list contains the most recent 20 lines extracted from the chat.
No. I just want to scroll through both of them to find out if there are lines that have not been displayed before. After the cycle, residues in the selected lines are processed by the following function.
Problem: when I get stuck on this loop, I get a badpointer after a while. What for? Bonus: Does anyone have a better solution to this problem?
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);
}
}
Lumpi source
share