This is my text file (mytext.text
):
rho_0,10 kp_0,8 Beta_kp,6 x_min,5 x_max,8 y_min,9 y_max,5 z_min,4 z_max,7
I want to read from this text file line by line, and store each value in the parameter at the same line.
For example, for the first line, store 10
in rho_0
.
I have written this code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line;
ifstream myfile("mytext.txt");
if (myfile.is_open())
while (getline(myfile, line))
{
cout << line << endl;
}
}
But I don't think it will save the value for the corresponding parameter.
I know that I should split each line by delimiter, and then convert string to double
(float
), but I don't know how to implement it for each line.