- #1
madtraveller
- 28
- 0
Homework Statement
I have 1 class for reading parameter from file (example below) and 1 class for doing calculation
For every step, I'd like to read in parameter and do calculation in between.
For i = 0 to number of lines in parameter file
Read in parameter;
Calculation;
End
My problem is that I don't know how to read a file continuously. Every time I called the function in parameter class, it just received the first line :(
Could anyone give me some suggestion?
Thank you
* Sample parameter file
Code:
m TD T V Sa Sb
0.5 246.6 39.6 6.1 0.4 0.6
0.5 394.8 39.7 4.6 0.9 0.2
0.0 391.3 39.0 3.6 1.0 0.6
0.4 350.1 39.0 8.8 0.6 0.3
0.3 94.1 38.9 6.0 0.6 0.7
0.5 95.0 38.5 7.2 1.0 0.0
0.3 86.4 39.3 3.4 0.4 0.4
0.5 404.5 39.8 0.9 0.9 0.3
0.4 252.7 39.3 7.9 0.6 0.4
0.5 1.3 39.9 2.4 1.0 0.7
0.2 36.0 39.9 3.5 0.4 0.5
...
The attempt at a solution
Parameter class:
Code:
bool parameters::get_parameter_from_file(const string &filename)
{
ifstream inputfile(filename.c_str());
if ( !inputfile )
{
cerr << "Error: file could not be opened" << endl;
return false;
}
string dummy_string; // temporary string to store unnecessary words
// read through the header
inputfile >> dummy_string >> dummy_string >> dummy_string
>> dummy_string >> dummy_string >> dummy_string;
// read parameters
inputfile >> m >> TD >> T >> V >> Sa >> Sb;
inputfile.close();
return true;
}