You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having some trouble with the no_header() option in this CSV parser, when using the CSVReader object. I am using MinGW64 on Windows 10.
Please see the code below to illustrate my problem. The code should:
Create a string with CSV formatted data, and save it into a file.
Print the contents of that string.
Create the format object we want (with no_header)
Parse the CSV file on disk
Parse the CSV string
I expect steps 2, 3, and 5 to print comparable results (all three rows). However, in step 4, we have trouble parsing the CSV file from disk. The no_header() option appears to be ignored.
#include<iostream>
#include"csv.hpp"usingnamespacecsv;// Method for printing the fields of the CSV with spaces in between.voidprintCSVFields(CSVReader& reader)
{
for (CSVRow& row:reader) {
for (CSVField& field:row) {
std::cout << field.get<>() << "";
}
std::cout << std::endl;
}
}
intmain()
{
// 1. Create a CSV string and write it to a file:
std::string csvString = "1, 2, 3\n4, 5, 6\n7, 8, 9";
std::string fileName = "test.csv";
std::ofstream outFile(fileName);
outFile << csvString;
outFile.close();
// 2. Print the csvString
std::cout << "Contents of csvString:\n" << csvString << "\n";
// 3. Create the format we want to use (no header)
CSVFormat format;
format.no_header();
// 4. Try reading the CSV from the file
CSVReader myFileReader(fileName, format);
std::cout << "\nReading from CSV file (step 4):\n";
printCSVFields(myFileReader);
// 5. Try reading the CSV from the string
CSVReader myStringReader = parse(csvString, format);
std::cout << "\nParsing from csvString: (step 5)\n";
printCSVFields(myStringReader);
}
I observe the same issue with a file without headers and variable line length.
But besides the header line, other lines are also discarded (which has probably to do with the variable line length?)
It works as expected when using std::ifstream or std::stringstream
This issue appeared for me after upgrading to 2.1.0.
I did not have problems with 2.0.1, but there I had to define a pseudo header in format for it to work
Hi!
I am having some trouble with the
no_header()
option in this CSV parser, when using the CSVReader object. I am using MinGW64 on Windows 10.Please see the code below to illustrate my problem. The code should:
format
object we want (withno_header
)I expect steps 2, 3, and 5 to print comparable results (all three rows). However, in step 4, we have trouble parsing the CSV file from disk. The
no_header()
option appears to be ignored.Output
The text was updated successfully, but these errors were encountered: