I need my program to find the exact amount of data to be stored into an array without asking the user. I am having trouble with this because my program will not run unless it knows how much data is going into the array. The program opens up a simple .txt file with numbers in it (ex. 9.8 4.5 2.4 8.7…). The amount of numbers will be random and I cannot waste any memory space (therefore I cannot declare the array size to be [10000]). So how to I get my program to open the notepad file, then count the amount of numbers, and then put those numbers into an array to be worked with later on in the program?
Here is my code with all the other, non-array, information taken out to make it much smaller to look at and work with. My problem with this program is hard to explain so I hope I have explained it well enough.
edit: I need to use an array! No vectors or alternative methods please.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
double scores[ARRAYSIZE];
int main()
{
ifstream infile;
infile.open(“scores.txt”);
int i = 0;
while (infile)
{
infile >> scores[i];
i++;
}
infile.close();
return 0;
}