Hi I am having a problem reading in a 2D array from a file. I will attach a phot
ID: 3541416 • Letter: H
Question
Hi I am having a problem reading in a 2D array from a file. I will attach a photo of the .txt file. What I am trying to do is read the names of the customers into a 1D array and read the rating values into a 2D array....... this is the code I have so far and it is giving me all kinds of garbage. Can someone please help!!? The second for loop I am just trying to display the array to make sure that it is stored correctly. The first set of for loops I am actually trying to store.
for (int x = 0 ; x < 86 ; x++)
{
getline( inFile , cust[x] );
for (int y = 0 ; y < 55 ; y++)
{
inFile >> ratings[x][y];
}
}
for (int x = 0 ; x < 86 ; x++)
{
cout << cust[x] << endl;
for (int y = 0 ; y < 55 ; y++)
cout << ratings[x][y] << " ";
}
Explanation / Answer
for (int x = 0 ; x < 86 ; x++)
{
inFile >> cust[x] ;
for (int y = 0 ; y < 55 ; y++)
{
inFile >> ratings[x][y];
}
}
//try like this,. might be buffering difference b/w getline and getting input from file...