-2

I have two for loops inside a while loop but when I execute the program, the while loop just becomes an infinite loop. Here is my code:

    while (!inFile1.eof()){

       for (int row = 0; row < 5, row++;){
            for (int column = 0; column < 5, column++;){

            getline(inFile1, fileData, (','));

            matrix1[row][column] = stoi(fileData);

            cout << matrix1[row][column];

            }
        }       
    }

I'm new to C++ so maybe I have made a silly error but I'd appreciate any help

The Gibbinold
  • 229
  • 2
  • 12
  • I have been working on an answer and you deleted your previous question at the minute I was about to post a response. – ilim Dec 14 '16 at 10:08
  • Read about why `while (!inFile1.eof())` is wrong [here](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong). – molbdnilo Dec 14 '16 at 10:09
  • I recommend you undo the removal of your previous question and we can continue on that one. – ilim Dec 14 '16 at 10:12

1 Answers1

3

You have stray commas in your for loops, which you should replace with semicolons:

int row = 0; row < 5; row++;

int column = 0; column < 5; column++;

Currently the stopping condition is row < 5, row++, which is the same as row++ due to the way in which the comma operator works.

Eventually your int will overflow and then you're in undefined behaviour land.

Bathsheba
  • 220,365
  • 33
  • 331
  • 451