I have a file containing lines of the form,
double mass, string seq, int K, int TS, int M, [variable number of ints]
688.83 AFTDSK 1 1 0 3384 2399 1200
790.00 MDSSTK 1 3 1 342 2
I need a (preferably simple) way of parsing this file without boost. If the number of values per line had been constant then I would have used the solution here.
Each line will become an object of class Peptide:
class Peptide {
public:
double mass;
string sequence;
int numK;
int numPTS;
int numM;
set<int> parents;
}
The first three integers have specific variable names in the object while all the following integers need to be inserted into a set.
I was fortunate enough to get two really awesome responses but the run time differences made the C implementation the best answer for me.
The best way I know of to parse an ascii text file is to read it line-by-line and use strtok. It’s a C function, but it’ll break your input into individual tokens for you. Then, you can use the string parsing functions atoi and strtod to parse your numeric values. For the file format you specified, I’d do something like this: