csv-parser icon indicating copy to clipboard operation
csv-parser copied to clipboard

Incorrect n_rows() value when using iterators to loop over the data

Open sjoubert opened this issue 4 years ago • 1 comments

When using iterator (either old style begin()/end() or through a range-for loop) the value returned by n_rows() is off by 1. This does not happen when using the read_row pattern in a loop.

From what I can tell, the issue seems to come from CSVReader::begin() which gets a data row and construct the first iterator without incrementing the counter. Later ++ calls on the iterator correctly do that through a read_row call.

A possible fix may be to just replace the current approach of begin with a call to read_row instead of explicitly retrieving the data.

sjoubert avatar Jun 24 '21 09:06 sjoubert

This may be the cause of #151 depending on the loop method used there.

sjoubert avatar Aug 06 '21 08:08 sjoubert