Reading txt file into 2D Array.

Got a program that needs to read data from temps.txt. For some reason when I test it with temp[1] and temp[2] I get random jibberish numbers.

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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

ifstream inFile;
int temps[2][12];
int col;
int row;


int main(int argc, char *argv[])
{
    
inFile.open("temps.txt");    
    
for (col = 0; col < 12; col++)
{
    for (row = 0; row < 2; row++)
    {
    inFile >> temps[col][row];
    inFile.ignore(1, 'n/');
    }

}


cout << temps[1] << temps[2];

inFile.close();

    system("PAUSE");
    return EXIT_SUCCESS;
}



Text file is: temps.txt

34 22 44 50 65 70 81 99 85 70 58 55
-3 1 12 23 40 50 55 60 52 48 30 22

2 rows and 12 columns.


can anyone shine some light?

thanks.
Last edited on
Topic archived. No new replies allowed.