360toPerspective/cpp/include/csv_parser.hpp

26 lines
1,017 B
C++
Raw Normal View History

#ifndef H_CSVparser
#define H_CSVparser
#include <vector>
#include <string>
/**
* @brief Parses a CSV file containing floating-point numbers.
*
* @param filename The name of the CSV file to parse.
* @return A vector of vectors of doubles containing the parsed data.
* Returns an empty vector if there was an error.
*
* This function reads a CSV file containing floating-point numbers and
* returns the data as a vector of vectors of doubles. The CSV file should
* use commas as delimiters and should not contain any quotes or other
* special characters. Each row in the CSV file should have the same number
* of columns. If there is an error opening the file or parsing the data,
* this function returns an empty vector and prints an error message to
* standard error. The error message will indicate the type of error and
* the name of the file where the error occurred.
*/
std::vector<std::vector<double>> parse_csv_file(const std::string& filename, char delimiter = ',');
#endif