4

I'm looking for a nice modern C++ CSV library, mostly for parsing.

Required features:

  • Written in modern C++ (C++11 at least)
  • Gratis
  • Libre
  • Fast (yes, this may be difficult to quantify)

Desired feature:

  • Header-mostly
  • Support for a wide variety of CSV syntax errors, trying to recover as much information as possible
  • Template-based policy for extra optimization
  • Optionally multi-threaded
  • Header-only
  • Support for non-comma separators
  • Tested for compliance with the CSV standard
  • Does not reinvent the wheel - uses the C++ standard library, Boost or other well-regarded libraries where relevant.
  • Supports reading only a part of a CSV file, e.g. a range of records/lines
  • Well-documented
  • "Elegantly" coded
  • Support for writing CSVs as well as reading/parsing them
  • Supports simplifying assumptions indicated by the user, e.g. whether the quoted strings may have field and record separators and/or escaped quotes within them; field data types; field widths.

1 Answer 1

6

Two libraries that fits the requirements and several of desired features:

I start to test them few days ago, so I can not confirm all the features, however I can point to detais that are defining my choice:

  • Rapidcsv is what I'm currently using, it allows to load data as vectors, and you can obtains row-vectors, that is common, and column vectors, that is what I'm looking for. It has two missing feature for that I made a fork and propose (very simply) improvements: 1 handling retrieve of vectos of just char items like std::vector (my data is composed of spatial time series discretized using SAX, that results in a symbolic binning values for instance from a to z), and 2 have functions that return the column and row counts

  • CSVstream retrieve data as a map of fector, that is good for CSV but in my case column names are not important and std:.map does not keep the order of the inserted data, an for my case I need to keep the original column order because column positions represent the spatial position - UPDATE: It can be a new feature: https://github.com/awdeorio/csvstream/issues/13#issuecomment-350701247

  • Fast C++ CSV Parser can not be used in my case because the number of columns needs to be known at compile time

This evaluation is very initial, the tree libraries appears very good to me so I suggest to test them to see what best fits your neesd

3
  • Can you describe these two libraries in a few sentences? Say something about their differences?
    – einpoklum
    Dec 10, 2017 at 8:38
  • Yes, I'm looking for something similar for my use case, so I have not a big experience with them, but I can add some tips, in the answer
    – campisano
    Dec 11, 2017 at 10:44
  • @einpoklum I made a confusion between CSVstream and FastC++CSVParser, Imade an update too for CSVstream
    – campisano
    Dec 12, 2017 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.