Getting numbers from a data file

I do not have a code that I need help with. I would like to ask how do I get a line of numbers from a data file with multiple rows of six number lines.
for example 4 5 6 2 3 4. Then extract each number and assign them to a variable r1,r2,r3,r4,r5,r6 respectively to be used in a formula.

1
2
3
  input_file.open("Q2.dat");

// where do I go from there? 


Last edited on
Don't use .open() and .close(), use curly braces instead:
1
2
3
4
5
6
7
8
9
10
11
12
13
//...code...

{
    std::ifstream infile ("Q2.dat");
    int r1, r2, r3, r4, r5, r6;
    while(infile >> r1 >> r2 >> r3 >> r4 >> r5 >> r6)
    {
        //...formula...
        std::cout << r1 + r2 - r3 * r4 / r5 ^ r6 << std::endl;
    }
} //infile automatically closed here

//...code... 
Last edited on
Topic archived. No new replies allowed.