Using 2d dynamic array to read in file

This is my first project using a 2-d dynamic array where we have to read the file into the array and I am having trouble with it.

We have to us dynamic arrays to create the array of numbers and assume the array would never be greater than 20 x 20 in dimension. Once we have read the file into the dynamic array we have to find the matrix sum.


I was trying to figure out how to read the numbers in the dynamic array to I can search each row for later. I hope someone can help.
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
 
int main (int argc, char* argv[]){


    int** a;
    int cnt = 0,size1 = 0, size2 = 0;

    ifstream fin;  
    fin.open("Numbers.txt");
    if(fin.fail()){
                  cout <<"error.\n";
    }
    else{ 
        
     
    a = new int*[size1];
    for (int row = 0; row < size1; row++){
         a[row] = new int[size2];
}
         for (int row = 0; row < size1; row++){
            for (int col = 0; col < size2; col++){  
                fin>>a[row][col];
              }
       for (int row = 0; row < size1; row++){
        for (int col = 0; col < size2; col++)
            cout<<a[row][col];
            cout<<endl;

    }
      fin.close(); 
      

}

}

return 0;
}


Last edited on
Topic archived. No new replies allowed.