dynamic arrays and files?

Hey Y'all, I am having a bit of trouble. I'm suppose to open a file and then read each data set, allocate an array big enough, and then read the data into the array. The file looks like this. It has a header to tell you how many values are in each set then the data:

Ill have to use this array to find the min, max and average for each data set but thats not my problem. I am having trouble reading each data set into the dynamic array.

Heres my code so far:
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
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
    int nums; 
	char array[100];
	float *data = NULL;


	ifstream inFile;
	inFile.open("datasets.txt");
	
		inFile >> nums;
		inFile.getline(array,100);
		
	data = new float[nums];
 
	for(int i = 0; i < nums; i ++)
	{
		inFile >> data[i];
		cout << data[i] << endl;
	}


		inFile.close();

    delete[] data;
    return 0;


Thanks!!
Last edited on
Topic archived. No new replies allowed.