readin two lines of file in one iteration

Discussion in 'C' started by heidik, Nov 8, 2010.

  1. heidik

    heidik New Member

    Joined:
    Oct 23, 2010
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    0
    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;
        }
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice