Is it possible to read two lines of a file in one iteration based on some condition? The files has several blocks of data where each block contains two consecutive lines having ORDER ID in it. I want to store each of these IDs for each block of data in two different variables e-g
Code:
string ordID_1,ordID_2;
Code:
ordID_1,ordID_2
Code:
ordID_1,ordID_2
The file contains data like
[output]
0:1:ORDER ID:0001VVYF
0:2:ORDER ID:0001VW1S
... another line ...
... another line ...
... another line ...
... another line ...
... another line ...
0:0:2nd-ORD-TO-WASH-TIME-DIFF,500.881
then a similar block appears again in the file
1:1:ORDER ID:0001VVYF
1:2:ORDER ID:0001VW1S
... another line ...
... another line ...
... another line ...
... another line ...
... another line ...
0:0:2nd-ORD-TO-WASH-TIME-DIFF,501.991
... and so on ...
[/output]
and this is the code I have so far.
Code:
while(getline(is,line))
{
size_t pos = line.find("ORDER ID");
if (pos != string::npos)
{
string ordID_1,ordID_2;
stringstream ss(line);
const int n_colons = 3; // number of colons to skip
for (int i=0; i<n_colons; ++i)
{
getline(ss,line,':');
}
getline(ss,line); // rest of line after the "n_colons" colons
cout << "line = " << line << endl;
}
}
