This command-line utility converts CSV database files into C/C++ header files - to #include them and immediately start to develop on structured, well-formed datasets. This skips error-prone steps like file delivering, loading, parsing, converting, and checking.
- Export or download your database in CSV file format, e.g. to: pizzas.csv
- Edit the CSV file and add datatype hints to the header line, e.g.:
Company, Pizza_Name, Type, Size, Price ($) - Convert by executing:
csv2hpp pizzas.csv pizza > pizzas.hpp. - Add the generated header file to your project (#include "pizzas.hpp") and start to develop.
- Build csv2hpp by executing:
cd src && cmake . && make(just requires cmake and a C++ compiler) - Datatype hints are mapped to C/C++ datatypes as follows:
(std::string)→std::string,(double)→double, no datatype is a string,(skip)skips the entire column. See all 87 supported datatype hints in: datatype_hints.csv - Empty CSV data cells are mapped to "" for strings and to 00 for everything else (as a hint).
- Precision hints such as '±05' are removed in float or double values (not supported in C/C++).
- Supports also big .CSV files: omits whitespaces, removes trailing '0'. It's recommended to use 'const char*' instead of 'std::string' which can break some compilers.
- Please find 8 more examples in the 📁examples subfolder.
- Contributions, suggestions, and improvements are welcome!
- Open an Issue if you encounter bugs or have feature ideas.
- Create a Pull Request if you'd like to improve something.
This open source project is licensed under the CC0-1.0 license. All trademarks are the property of their respective owners.