I have a .txt file that is formatted as follows:
906 25 25
1997 25 25
900 25 25
1990 50 1.75
1981 50 50
925 25 25
I have written the following code to read the numbers into an array:
float numbers[1029][2];
std::ifstream fin;
fin.open("GiftCardFinal.txt");
if (!fin.is_open())
{
return 0;
}
for (int i = 0; i < 1029; i++)
{
for (int j = 0; j < 3; j++)
{
fin >> numbers[i][j];
}
}
fin.close();
However, when I run this code to test if it read the numbers correctly...
std::cout << numbers[0][0] << " ";
std::cout << numbers[0][1] << " ";
std::cout << numbers[0][2] << " ";
std::cout << std::endl << std::endl;
std::cout << numbers[1][0] << " ";
std::cout << numbers[1][1] << " ";
std::cout << numbers[1][2] << " ";
It outputs:
906 25 25
25 1997 25
Can anyone help with this or offer advice on what I can improve?
std::cout << numbers[0][2]goes outside the boundaries of the 2nd array dimension.j < 3