//Reads 2 arrays from inFile.txt 
//Each array is stored in a line
//First line read in then input from line with istringstream
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

using std::ifstream; //input file stream
using std::endl;		//end of line character
using std::cout;		//screen output stream
using std::setw;
using std::istringstream; //input from string stream
using std::string;

void readStreamArray(ifstream& in, double a[])
{
	cout << "Entering readStreamArray: " << endl;
	string s;
	getline(in, s);
	//validation of input from file input in
	cout << "getline() read from file input string \n" << s << endl;
	
	//string stream defined and given getline input in s
	istringstream inString(s);

	//Read array from string stream
	cout << "Array read in from string stream is " << endl;
	double number;
	bool more = true;
	int i=0;
	while (more){
		inString >> number;
		if (inString.fail())	
			more = false;		   
		else{
			a[i] = number;
			cout << setw(7) << a[i];
			if (i % 10 == 9)//print array 10 elements/row
				cout << endl;
			i++;
		}
	}
	cout << "\nExiting readStreamArray " << endl;
}

int main(){
	ifstream in; //input stream in declared
	in.open("inFile.txt"); //in connected to file inFile.txt

	double a[200];
	cout<< "main: calling readStreamArray for array a " << endl <<endl;
	readStreamArray(in, a);


	double b[200];
	cout<< "main: calling readStreamArray for array b " << endl << endl;
  readStreamArray(in, b);

	in.close();
	return 0;
}