Sundevil65
Programmer
I'm trying to read a line of numbers from a "file.dat". (i.e., 2 66 78 3 45 23 65). I need to read the value of single digit and count the numbers after it. Of course I'm the fstream ios. Thanks
++++++++++++++++++++++++
#include <iostream.h>
#include <fstream.h>
#include <assert.h>
#include <iomanip.h>
int main ()
{
int reading;
ifstream inStream;
inStream.open("average.dat"
assert (inStream.is_open());
while (! inStream.eof()){
inStream >> reading;
int sum = 0;
int i;
int avg = 0;
//int count = 0;
for (int index = 0; index < 5; index++){
sum += reading[0];
//count++;
}
cout << sum << endl;
cout << index << endl;
//avg = sum/index;
//cout << sum << avg << endl;
}
inStream.close();
return 0;
}
++++++++++++++++++++++++
#include <iostream.h>
#include <fstream.h>
#include <assert.h>
#include <iomanip.h>
int main ()
{
int reading;
ifstream inStream;
inStream.open("average.dat"
assert (inStream.is_open());
while (! inStream.eof()){
inStream >> reading;
int sum = 0;
int i;
int avg = 0;
//int count = 0;
for (int index = 0; index < 5; index++){
sum += reading[0];
//count++;
}
cout << sum << endl;
cout << index << endl;
//avg = sum/index;
//cout << sum << avg << endl;
}
inStream.close();
return 0;
}