Hello,
I am trying to load data from a testfile.txt file which contains ten records and 3 fields with numbers into a 2 dimensional table and then print it.
I am not sure if I am accesing the data correctly and placing it into the array. I get no output.
first time posting hope I enclosed the code properly
Would appreciate any help,
Thanks
Nu
Here is the code:
#include "stdafx.h"
#include <fstream>
using std::ifstream;
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::cerr;
using std::ios;
#include <cstdlib>
using std::exit;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int ROWLIST=10;
const int COLLIST=3;
int inputARRAY[ROWLIST][COLLIST]={0};
ifstream inputFile( "textfile.txt", ios::in);
if ( !inputFile )
{
cerr << "file could not be opened" << endl;
exit(1);
} // end if
int row=0;
int col=0;
while( !inputFile.eof() )
{
for ( row=0; row < ROWLIST; row++)
for ( col=0; col < COLLIST; col++)
inputARRAY[row][col];
}
for ( int r=0; r< ROWLIST; r++)
for ( int c=0;c<COLLIST;c++)
cout << inputARRAY[r][c] << endl;
return 0;
}
textfile.txt
12 72 87
11 71 81
6 70 78
19 70 89
38 71 109
35 72 110
1 72 73
8 72 81
9 72 83
5 71 76