I don't quite understand how to get an input file to fill an array. It's part of a much bigger program, and I need this file (filled with 20 numbers) to be read in it's entirety (an eof?) to an array.
Printable View
I don't quite understand how to get an input file to fill an array. It's part of a much bigger program, and I need this file (filled with 20 numbers) to be read in it's entirety (an eof?) to an array.
So what have you tried? Do you know anything about arrays?
I understand arrays pretty well. It's combining one with an input file that confuses me.
Here is what I have so far:
Code:void fill_array(int a[],int size, int& number_used)
{
int next,index =0;
using namespace std;
ifstream in_stream;
in_stream.open("SUPERNUMBERS.txt");
if(in_stream.fail( ))
{
cout << "In stream failed.\n";
exit (1);
}
in_stream.get(next);
while (! in_stream.eof( ))
{
a[index] = next;
index ++;
cin >> next;
}
number_used = index;
}