Commit iniziale: è presente una base del progetto con joint di base

This commit is contained in:
2026-05-30 22:58:06 +02:00
parent 62fbb000d8
commit 30c8f35b28
81 changed files with 113139 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
class CSVProcessor {
private:
std::vector<std::string> headers;
std::vector<std::vector<float>> data;
public:
// Method to read CSV file and store data in vectors
void readCSVFile(const std::string& filename);
// Getter for headers
const std::vector<std::string>& getHeaders() const;
// Getter for data
const std::vector<std::vector<float>>& getData() const;
};
+53
View File
@@ -0,0 +1,53 @@
#include "../headers/csv.hpp"
void CSVProcessor::readCSVFile(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open()) {
throw std::runtime_error("Could not open file: " + filename);
}
std::string line;
// Read headers (first line)
if (std::getline(file, line)) {
std::stringstream ss(line);
std::string header;
while (std::getline(ss, header, ',')) {
headers.push_back(header);
}
}
data.clear();
// Read data
while (std::getline(file, line)) {
std::vector<float> row;
std::stringstream ss(line);
std::string value;
while (std::getline(ss, value, ',')) {
try {
row.push_back(std::stof(value));
} catch (const std::invalid_argument& e) {
// Handle non-integer values if needed
row.push_back(0); // or some other default/error value
}
}
data.push_back(row);
}
file.close();
}
// Getter for headers
const std::vector<std::string>& CSVProcessor::getHeaders() const {
return headers;
}
// Getter for data
const std::vector<std::vector<float>>& CSVProcessor::getData() const {
return data;
}