Hi everyone, I'm working on an assignment that is required to use a 2D array to store data from a text file for a maze and then it should use a queue to solve the maze. I think i have the right idea with storing the maze in the array, but when I go to print it, it seems that it prints an empty array. It's probably a simple fix but I'm not seeing it. Any guidance on how to fix this issue would be much appreciated. Thanks in advanced. Here is my code for the 2D dynamic array:
it prints the output all on one line instead of in a square. When I add an "endl" at the end of the "cout" it prints every individual character on its own line. I gotta be just overlooking something obvious here.
Are you sure it's storing them correctly? When I write cout << maze; it still prints out the entire array on a single line and then 4 more blank lines after that, as the dimensions read from the data file are 5 by 5. To me it looks as if the entire text file is being stored in the first element of the array and I can't figure out why it's behaving this way. So far I've tried adding spaces after the print statement, using the setw() function, changing the placement of my print statement and it keeps giving me incorrect output. When I do cout << maze I get the following output:
1 2 3 4 5 6 7 8
Reading # of rows and columns...
Nevermind about the 4 extra lines, I forgot about that extra cout << endl; within the outer for loop. Also, I figured out that having while(ifile) within both for loops right before the read and print statements is what was causing the weird output all one line. Could you explain to me why that is?