File trouble

having some trouble with my program reading the file im trying to have it read this is what I have so far. it keeps displaying 1 when it should display -15

[code]
ifstream infile;
infile.open("math.dat");
infile<<value1;
cout<<"value1"<<endl;
[code]
>> is for input. << is for output.
yea sorry i fixed that and it still gives me the wrong number now it gives me 32560 when it should give me -15

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ifstream infile;
            infile.open("math.dat");
            cout<<"Reading data from file"<<endl;
            inFile>>value1;
            inFile>>value2;
            inFile>>value3;
            inFile>>value4;
            inFile>>value5;
            inFile>>value6;
            inFile>>value7;
            inFile>>value8;
            inFile>>value9;
            inFile>>value10;
            inFile.close();
            cout<<"value1"<<endl;

Given what you are trying to do its more effective to use a while loop to read the file. You can use an array if you know how many values are in the file or just use a vector.


Show the content of the "math.dat" file.

Aceix.
Topic archived. No new replies allowed.