The following is a function that compiles just fine, but when I run it, I get a "Debug Assertion Failed" and it says "list iterator not dereferencable". As far as I can tell the error occurs at whileIter++. I've looked at examples of iterators and how they are used, and can't figure out what I'm doing wrong.
CString findImage(CString fileName, list<record> csvFile)
{
std::list<record> tmpCsvFile = csvFile;
std::list<record>::iterator tmpIterator = tmpCsvFile.begin();
list<record>::iterator whileIter = tmpCsvFile.begin();
fileName = fileName+".txt";
while (whileIter != tmpCsvFile.end())
{
whileIter++;
if (fileName == (whileIter->fileName).c_str())
break;
}
return whileIter->characters.c_str();
}
Basically there is a list of records ( a struct with a few members, one of which is fileName). The function should compare the fileName in each record of the list, with the fileName that was passed as a parameter to the function in the hope of finding two that are equal.
Thanks in advance