It isn't hard if format is constant.
First line is very simple. I don't think I need to explain it.
The second one is more complicated.
method 1: using stdlib
use file.ignore(4, ' ') to remove 'm1: '
then read 'pt,eta,phi,m=' into a string (with file >>)
then in that string find ','. split the string when you find it.
store the left part somewhere, repeat the process with the left one.
when you can't find ',' remove '=' that is in the end and read 4 numbers (with file >>)
then read a string (>>) and remove ':' from it. read the last number.
then read the '\n'
method 2: doing it yourself
1 2 3 4 5 6 7 8 9 10 11 12
|
char c;
while(file){
c = file.get();
if(c == ' ') break;
}
string str;
while(file){
c = file.get();
str.append(c);
if(c == ',' || c == '=') break;
}//repeat 4 times
//then do as in previous
|
method 3:
both of those aren't great though. stdlib is not really designed for parsing. Your own functions have potential to be more flexible, but doing everything yourself isn't comfortable. You should probably look into some special library. maybe boost::regex. (edit: note: I really don' know anything about it)