Count rows without processing them?
Closed this issue · 1 comments
dominique120 commented
Is there a way or a function already implemented to be able to count the rows of the file without processing each line first?
This would be very helpful to be able to handle error thrown by read_row()
individually instead of failing the whole file.
dominique120 commented
I ended up finding a solution by doing the following:
size_t lines = 0;
io::LineReader ln_reader("file.csv");
while (char* line = ln_reader.next_line()) {
++lines;
}
...
for (size_t i = 0; i <= lines; ++i) {
try {
in.read_row(...);
} catch (io::error::too_many_columns::exception) { // or other exceptions
//handle exception
}
}