| | |
list iterator not dereferencable
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 17
Reputation:
Solved Threads: 0
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.
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
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: May 2008
Posts: 538
Reputation:
Solved Threads: 86
Your problem is inside the while loop.
You have advanced the iterator (possibly to the end) before you try to test the filename. Put the fileName test (with the break) before the iterator advancement.
c++ Syntax (Toggle Plain Text)
while (whileIter != tmpCsvFile.end()) { whileIter++; if (fileName == (whileIter->fileName).c_str()) break; }
You have advanced the iterator (possibly to the end) before you try to test the filename. Put the fileName test (with the break) before the iterator advancement.
![]() |
Similar Threads
- Double linked List Iterator InsertAfter Function (C++)
- Implementing Linked List iterator, gcc is acting wierd (C++)
- Use of Iterator to access/ Search STD List ..need help! (C++)
- Radio Button and List (JSP)
- Use of Iterator (Java)
- Non dereferencable iterator C++ (C++)
- traverse function doubly linked list (C)
Other Threads in the C++ Forum
- Previous Thread: Help With this program
- Next Thread: Classes and Linked Nodes
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





