inFile reading help

Hello, I always used this site to look for things i did not understand or was trying to figure out at that time. Till today where everything i tried was not working. My file opens and YES the file is in the right folder. It compiles with no errors but my output is not correct... not even close to being correct... my file has 21 numbers from 1-21 in order...and yes i saved it as a .dat file too.


#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

int main(){
const int ARRAY_SIZE=21;
double testScores[ARRAY_SIZE];
int count=0;
//string file;
ifstream inFile;
ofstream outFile;
inFile.open("p7.dat");
if(inFile.is_open())
{
cout <<" opened\n";

while(!inFile.eof() &&inFile >> testScores[count])
{
count++;
}
for(int i=0; i<20; i++)
{
cout << testScores[i];
}
}
else
{
cout << "file not opened";
}
return 0;
}


and my exact output...

opened
02.07541e-3172.12942e-317nan01.13298e-3172.1018e-3172.10142e-3173.23786e-3191.4822e-3236.91692e-3221.13301e-3172.10151e-3172.10142e-3172.07512e-3171.58543e-31702.41553e-3171.9098e-313
Last edited on
I ran you program and looks like I got the right output.

C:\Temp>test125
opened
1234567891011121314151617181920

I added a << endl; to put it each on a new line and it looks like this.
C:\Temp>test125
opened
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


the data file looks like

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21



I'm guessing something is wrong with your input file.

I'm totally confused now. I made over 20 files and I'm still getting the same style of output. Can you send me the file you used?
Topic archived. No new replies allowed.