Hello, I am currently doing an assignment where I have to read numbers from a .txt document into an array and later find the average of different lines of the .txt document sort them and what not. I'm not even close to the ladder parts of this assignment and I am stuck just getting the information in the .txt to the array. The .txt document looks like this:
3
3.55 2.55 1.55 4.55 5.55
4.55 3.55 2.55 5.55 6.55
5.55 4.55 3.55 6.55 7.55
I need to get each horizontal line into the array and do calculations on each separate line. (Excluding the first 3)
So far I have this:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream> //header file for file functions
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// declare file objects
ifstream in_stream; //declare object that can read files
ofstream out_stream; //declare object that can write to files
// tell file objects which files to access
in_stream.open("Prog5.txt");
out_stream.open("Prog5out.txt");
// check that files can be accessed
if (in_stream.fail())
{
cout << "Input file opening failed. \n";
exit(1);
}
if (out_stream.fail())
{
cout << "Output file opening failed. \n";
exit(1);
}
double linecount = 0;
double arrayOne[20];
// numbers in file set to variable number
while(!in_stream.eof())
{
in_stream >> arrayOne[linecount];
linecount++;
}
// close file objects
in_stream.close();
out_stream.close();
}
I just have no idea what to do, I'm so lost. Any help would be appreciated, thank you.