csv parser, skip first line

goodday!!

i'm using the following code to parse a csv file and store the values in a 2d array:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Row
{
    public:
        int flows_len;          // number of rows to initialize the flows array
        string **flows;         // flows array
        int Num_flows;           // Number of flows parsed
        ifstream       file;
        
        void readNextRow(istream& str){     
            
          for (int j=0;j<flows_len;j++){
                string  line;
                getline(str,line);    

                stringstream   lineStream(line);
                string  cell;

            for (int i=0;i<47;i++){
                getline(lineStream,cell,',');      // get the comma separated strings-columns-fields
                flows[j][i]=cell;      // fill the flows array
                         }
                Num_flows++;             // number of rows-flows parsed ++
            }
        }
        Row (int num){                    // Class Constructor
        flows_len = num+1;
        flows = new string *[flows_len];
        for (int i=0;i<flows_len;i++){
        flows[i] = new string[47];}
        Num_flows=0;
        };
        
        ~Row (){cout << "~Row" << endl;};
   };

It's working great but i need to skip the first line with the field headers.

thanks!!
closed account (o3hC5Di1)
Hi there,

If I'm not mistaken you can skip a line using ignore() on the istream:

1
2
istream istr;
istr.ignore(500, '\n'); //ignore the first 500 characters, or until first \n, whichever is met first 


Hope that helps.

All the best,
NwN
1
2
istream istr;
istr.ignore(500, '\n'); //ignore the first 500 characters, or until first \n, whichever is met first 


cant figure it out..i'm using it before the for (int j=0;j<flows_len;j++) but keeps getting the first line!!
ok, my mistake, i 've put it in main(), before the function call and got rid of the first line

thanks!
Topic archived. No new replies allowed.