The first and second lines of the file will contain the
number of rows and the number of columns respectively. The remaining lines in the file will each
contain three integers representing the row, column, and data value for an element in the matrix.
If a particular matrix element is not listed the data value should be assumed to be zero.
This is the file:
3
5
0 4 22
0 3 3
1 0 -3
2 2 -10
2 1 7
2 0 18
1 1 25
0 2 -15
I dont have a problem deleting the ptr or opening the file, just reading the rows, cols and values into the matrix
If I understand your problem correctly your program misses out on three elements of the matrix. This line appears to me to be the problem. Give it a go and try your program without this line. :)
You will need to initialize the new matrix with zero values for each element.
Then,
1 2
inputFile >> i >> k >> value;
twoD[i][k] = value;
Then,
keep the two for loops just for printing out the matrix. So this means they should be outside the while loop. Note also this loop can be used for the initialize step. Instaed of cout etc, just write twoD[i][k] = 0;