cant read multiple inputs from a file

I'm trying to read multiple inputs from the file and seem to be failing can someone tell me what's wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
ifstream infile;
    infile.open(filename);
    if(!infile) {
        cout<< "Sorry Bad File. Run again with different file name " <<endl;
        exit(0);
    }
    else {
        cout<<"Reading file..." << endl;
    }

    Stack change;
    int temp[16];
    int i=0;

    while(!infile.eof())
    {
       infile>>temp[i];
       //change.push(temp[i]);
       i++;
    }
    infile.seekg(0);
    for(i=0;i<10;i++) {
        cout<<temp[i]<< " "; /* point of this for is just to see what is being stored in the file */
    }


contents of the file:
1, 10, 10, 5, 1, 25

honestly, it should work I just done see why it won't like all it is supposed to be doing is reading inputs from the file

Last edited on
Remove the commas from the file. operator>>() can't parse those.
@helios:
i did that it still wont work
Okay, so what does "won't work" mean? What happens?
@helios

here is the output:


1
2
3
4
Enter the name of the file
change
Reading file...
0   0 0 0 0 0 0 0 0 0 0
Last edited on
1
2
3
    for(i=0;i<10;i++) {
        cout<<temp[i]<< " "; 
    }


Reading file...
0   0 0 0 0 0 0 0 0 0 0


Count the zeros ...



while(!infile.eof())
Please don't use that.
Last edited on
Topic archived. No new replies allowed.