C++ CSV 解析器库
| Linux | Mac | Windows |
|---|---|---|
| Rapidcsv 是一款易于使用的 C++ CSV 解析器库。它支持 C++11 (以及 | ||
| 稍后),仅包含头文件,并附带基本的测试套件。 | ||
| 图书馆被列入了这本书中 | ||
| C++20 适用于程序员。 | ||
| 示例用法 | ||
| =========== | ||
| 这里有一个简单的示例,读取 CSV 文件并将 'Close' 列作为 | ||
| 浮点数向量。 | ||
| colhdr.csv 内容: |
Open,High,Low,Close,Volume,Adj Close
64.529999,64.800003,64.139999,64.620003,21705200,64.620003
64.419998,64.730003,64.190002,64.620003,20235200,64.620003
64.330002,64.389999,64.050003,64.360001,19259700,64.360001
64.610001,64.949997,64.449997,64.489998,19384900,64.489998
64.470001,64.690002,64.300003,64.620003,21234600,64.620003ex001.cpp 文件内容:
…cpp rapidcsv::Document doc("file.csv", rapidcsv::LabelParams()); rapidcsv::SeparatorParams(), new rapidcsv::ConverterParams(true));
Check if a Column Exists
------------------------
Rapidcsv provides the methods GetColumnNames() and GetRowNames() to retrieve
the column and row names. To check whether a particular column name exists
one can for example do:
cpp rapidcsv::Document doc("file.csv"); std::vector = doc.GetColumnNames(); bool columnExists = (std::find(columnNames.begin(), columnNames.end(), "A") != columnNames.end());
Handling Quoted Cells
---------------------
By default rapidcsv automatically dequotes quoted cells (i.e. removes the encapsulating
`"` characters from `"example quoted cell"`). This functionality may be disabled by
passing `pAutoQuote = false` in `SeparatorParams`, example:
cpp rapidcsv::Document doc("file.csv", rapidcsv::LabelParams()); rapidcsv::SeparatorParams(',/* pSeparator */, false
暂无开放 Issues,或尚未同步最近议题。