Hey,
I'm feeling I've searched the whole net, without finding any solution to my problem...
I want to read in a data-file, where the data is formatted like:
1 2 3 4
|
14_229: 3.0000000000000000e+00 -2.0000000000000000e+00 7.0461538461538325e-05 1.6910769230769201e-04
14_233: 3.0000000000000000e+00 -2.0000000000000000e+00 7.1692307692307553e-05 1.7206153846153815e-04
14_237: 3.0000000000000000e+00 -2.0000000000000000e+00 7.2923076923076781e-05 1.7501538461538430e-04
14_241: 3.0000000000000000e+00 -2.0000000000000000e+00 7.4153846153846009e-05 1.7796923076923045e-04
|
Now, I want to extract the data from the line beginning with "14_237" and store the following values into double-variables.
My last assumption, was to read every line in to a string via getline, it contains in the beginning "14_237".
1 2 3 4 5
|
string para = "14_237";
for(int i = 0; str.substr(0,7).compare(para)!=0; ++i){
getline(datastream,str);
cout << str <<" "<< str.substr(0,7).compare(para)<< endl;
}
|
This works, but then the problem begins... I haven't found any possibility to read formatted data from a c++-string. I tried to convert the string to an array, to use "sscanf"... despite i think this is an ugly work-around, i didn't get this working...
therefore, i hope someone out there has a solution for me ;)
greetings