File Reading

Hi,
I'm trying to iterate through a file and output each number as a double separately so I can input it into a multidimensional array and perform matrix operations on it.

1
2
3
4
5
6
7
8
9
10
11
12
13
    ifstream myfile;
    myfile.open(file); // Opens file
    istream_iterator<double> id(myfile);
    for (; id != istream_iterator<double>(); id++) {
        int j = 0;
        for (int i = 0; i < sizeN; i++) {
            Matrix[i][j] = *id;
            if(i == (sizeN - 1)) {
                j++;
                i = 0;
            }
        }
    }



It doesn't seem to be working though, it is getting stuck somewhere in there and I can't seem to figure it out.

Help please

NOTE : Iv been coding in C a bit so if what im doing here is totally wrong that might be the reason..

Thank you
well, you never get out of the loop on line 6 because you set i to 0 just before it reaches the end and you never check j for an end.

I suggest: use a second loop for j instead of doing that acrobatics on line 8
Topic archived. No new replies allowed.