Skip to content

Bug Report? no_header has counterintuitive behaviour #285

@belzebuu

Description

@belzebuu

I would expect that in CSVFormat the specification .no_header() include the first row (or row zero, in a zero-indexed setting) in the set of rows with data. Instead, I am unable to access the first row.

In the example that follows:

#include <string>
#include "csv-parser/single_include/csv.hpp"

using namespace std;
using namespace csv;

int main(int argc, char *argv[])
{
	string fileinstance(argv[1]);
	cout << "* Reading rows from " << fileinstance << "..." << endl;
	
	CSVFormat format;
	format.delimiter({'\t', ';'})
		.quote('"')
		//.header_row(0); // Header is on 0th row (zero-indexed)
		.no_header(); // Parse CSVs without a header row
						// .quote(false); // Turn off quoting
	
	CSVReader reader(fileinstance.c_str(), format);
	for (CSVRow &row : reader)
	{
		for (CSVField &field : row)
		{
			std::cout << field.get<>() << " ";
		}
		cout << endl;
	}
}

Executing it on a file with this content:

row     1
row     2
row     3

the output is the following.

* Reading rows from test.txt...
row 2
row 3

If this behavior is intentional it should be better specified. It caused me quite some hours of debugging to find out why some data were not read in my case.
Otherwise, great tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions