issue using Boost::Filesystem::recursive_directory_iterator

i have a task where i have to perform a certain comparison among all files in a directory. this is not that program. i'm familiarizing my self with the filesystem library first. however, i can't seem to get nested for loops to work. i changed the inner loop to a while loop so i could put checkpoints at each statement and see where it's failing. it fails when it reaches the very end of the directory. can anyone tell me why it is failing where it is?

i also omitted a bunch of code that is not relevant to this issue (and is commented out in my source file), so if it looks like this function doesn't actually do anything, well, it doesn't. except crash, of course.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <string>
#include <iostream>

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>
#include <boost/regex.hpp>

using namespace boost::filesystem; 
using namespace std;

void compareFileNames(const path &directory)
{
    if (exists(directory))
    {
        string i_direc,
               i_fileName,
               j_direc,
               j_fileName;

        recursive_directory_iterator start(directory), end, i(directory), j;
        int pasdf = 0, k = 0;
        for(i; i != end; i++, k++)
        {
            cout << k;  //counting for loop iterations
            while( is_directory(*i) )
            {
                i_direc = i->path().string();
                i++;
                if(i == end)
                    break;
            }

            i_fileName = i->path().leaf().string();
            //cout << i_fileName << endl;
            j = i;
            while(j != end)
            {
                cout << pasdf << endl; //counting while loop iterations
                
                
                cout << "herp";
                cout << j->path().string() << endl; 
                cout << " derp\n";              
                j++;
            }
        }
    }
}


it makes it through the first iteration of both loops and never makes it back into the for loop on the second iteration
Last edited on
for anyone who may look at this thread, the answer is fairly simple. j and i are pointers. the while loop ends because j is equal to end (as is i), then it returns to the for loop which increments i (and j) which are no longer equal to end, since they are past end and my program cries and so do i, but all is good now, cplusplus.com/forum
Topic archived. No new replies allowed.