Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   readin two lines of file in one iteration (http://www.go4expert.com/forums/readin-lines-file-iteration-t23798/)

heidik 8Nov2010 17:54

readin two lines of file in one iteration
 
Hello everyone.

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;
and then compare this pair of IDs (
Code:

ordID_1,ordID_2
) with the pair of IDs (
Code:

ordID_1,ordID_2
) in all the rest of the blocks. If the pair of IDs matches any of the pairs in the rest of the blocks then the two blocks would be called duplicates. Also there can be more than one duplicate for a block (not just one). Could anyone please help me with achieving this goal?

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;
    }
}



All times are GMT +5.5. The time now is 03:45.