M
Mike Copeland
How can I use cin to "reverse" the logic below?:
ostringstream oss2;
oss2 << cNoEvts << setfill('_') << setw(24) << left << EvLst1 << right
<< setfill('0') << setw(2) << nDivis
<< setw(4) << nBatch << setw(6) << sEntId << cEntIdx << setw(5)
<< sEnDate << cEntType << setw(5) << sTDate1 << cTCode1 << setw(5)
<< sTDate2 << cTCode2 << cRecCode << "1>" << endl;
That is, I format an output line and write it to a text file, but I
also need to read that file and parse the line's data fields according
to the format I create above. (I don't have any redesign option,
because the data file format is fixed and can't be changed - to comma-
separated-values that can be parsed.) Also, the data line is much more
complex than this code snippet shows, so there's a _lot_ of fixed-field
formatting being done here (50+ fields, >300 characters in the line).
I used to accomplish this this in the C-style: a very large sprintf
call and a single text line "read", followed by individual field parsing
and conversions (numeric fields, strings, individual characters, etc.).
I am trying here to use more state-of-the-art coding (without knowing if
there will be a performance hit or not...) - perhaps I'm taking the
wrong approach... Please advise. TIA
ostringstream oss2;
oss2 << cNoEvts << setfill('_') << setw(24) << left << EvLst1 << right
<< setfill('0') << setw(2) << nDivis
<< setw(4) << nBatch << setw(6) << sEntId << cEntIdx << setw(5)
<< sEnDate << cEntType << setw(5) << sTDate1 << cTCode1 << setw(5)
<< sTDate2 << cTCode2 << cRecCode << "1>" << endl;
That is, I format an output line and write it to a text file, but I
also need to read that file and parse the line's data fields according
to the format I create above. (I don't have any redesign option,
because the data file format is fixed and can't be changed - to comma-
separated-values that can be parsed.) Also, the data line is much more
complex than this code snippet shows, so there's a _lot_ of fixed-field
formatting being done here (50+ fields, >300 characters in the line).
I used to accomplish this this in the C-style: a very large sprintf
call and a single text line "read", followed by individual field parsing
and conversions (numeric fields, strings, individual characters, etc.).
I am trying here to use more state-of-the-art coding (without knowing if
there will be a performance hit or not...) - perhaps I'm taking the
wrong approach... Please advise. TIA