I have a file with data like this
10000 9.425 1.00216 -0.149976
20000 19.425 0.973893 -0.135456
30000 29.425 1.01707 -0.115423
40000 39.425 1.0181 -0.12074
.
.
.
to get the data what I am doing is to read the whole line and then separate the line by the spaces to get the data I need. The problem is that the file has 3000 lines so I tried to get the line in a for loop
std::vector<std::string> a;
std::ifstream datas("Data/thermo_stability.dat");
std::string str;
char d=' ';
for(int i=0; i<n; i++)
{
std::getline(datas, str);
tokenize(str,d,a);
x[i]=std::atof((a[1]).c_str());
y[i]=std::atof((a[3]).c_str());
std::cout << x[i] << "\t" << y[i] << std::endl;
}
I noticed that something was wrong so I added that cout and found out that it was always getting the same line. How can I fix this problem? Why is not getting the next line after getline is called? When I do it outside the loop it goes to the next line.
Aucun commentaire:
Enregistrer un commentaire