Hello, I need to take a file filled with numbers and input them into a two-dimensional array. The file would look like:
3 6
3.9 4.5 2.1 1.0 2.4 4.3
3.1 4.2 5.1 6.2 1.0 2.7
1.2 2.3 3.1 4.2 5.2 6.4
where the first two numbers are the vertical and horizontal dimensions of the array. I have to do this by using pointer and new.
Now, I've gotten it partly done, but I've gotten stuck reading the numbers into the array. Each row is the test scores for a student, so each horizontal array is a different student. It says I cannot convert float* to float in assignment, but I don't know exactly know how I can use pointers and what I am doing wrong. Below is my code. And yes, this is homework, but I have looked in my textbook, all over the web, and can't figure out what exactly I am doing wrong. Please help me. Thank you.
#include <iostream>
#include <fstream>
#include <cstdlib>
typedef float* Pointer_f_array;
int main ()
{
using namespace std;
ifstream in_stream;
char file_name_input[21];
int array_size_vertical;
int array_size_horizontal;
cout << "Enter the file name of your input file (maximum of 20 characters):\n";
cin >> file_name_input;
in_stream.open(file_name_input);
if (in_stream.fail( ))
{
cout << "Input file opening failed.\n";
exit(1);
}
in_stream >> array_size_vertical >> array_size_horizontal;
Pointer_f_array p;
p = new float[array_size_vertical];
for (int c = 0; c < array_size_vertical; c++)
{
p[c] = new float[array_size_horizontal];
}
for (int d=0; d < array_size_vertical; d++)
{
in_stream.getline (p[d], 100);//array_size_horizontal);
}
delete [ ]p;
in_stream.close ( );
return 0;
}