View Single Post
Join Date: Apr 2008
Posts: 47
Reputation: Cybulski is an unknown quantity at this point 
Solved Threads: 3
Cybulski's Avatar
Cybulski Cybulski is offline Offline
C++ wannabe

Re: Iterator assertion failure. How?

 
0
  #3
May 14th, 2008
Originally Posted by Ancient Dragon View Post
My guess is that neither of those loops will work.
1) how is iter_vsDirectory initialized? You failed to post it.

2) what is the purpose of that first loop with the iterator ? The iterator doesn't appear to be used anywhere within the loop. Adding more strings to the end of the vector might invalidate the iterator.

3) You have to call FindFirstFile() before you can start a loop for FindNextFile(). The FindNextFile() you have code will always fail.
1)
vector<string>::iterator iter_vsDirectory = v_sDirectories.begin();

2)
First loop is meant cycle trough directories. For each directory found in v_sDirectories it will call FindFirstFile, then internal loop to list files/directories inside. In case of dir found, it will append last setion of path to work recirsive in all directories inside one given at start.

If adding objects to vector invalidates iterator - thats not the way vector should work imo.

3)
It is called, before main loop.

There is result of running it:
  1. d:\test\*
  2. iterator: d:\test\*
  3. .. dir
  4.  
  5. directory1 dir
  6. Pushed back to dir vector: directory1\*
  7.  
  8. directory2 dir
  9. Pushed back to dir vector: directory2\*
  10.  
  11. file1.txt file
  12. file2.txt file
Last edited by Ancient Dragon; May 14th, 2008 at 9:22 am. Reason: corrected quote tags
Reply With Quote