BendCalc/src/DataLoad.cpp

41 lines
1.1 KiB
C++

#include "../include/BendData.h"
#include "../include/DataLoad.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
namespace DataLoad {
void loadDataFromCSV(const std::string& fileName, BendData& bendData) {
std::ifstream file(fileName);
if (!file.is_open()) {
std::cerr << "Failed to open the file: " << fileName << std::endl;
return;
}
std::string line;
while (std::getline(file, line)) {
std::stringstream ss(line);
std::string item;
std::vector<double> data;
while (std::getline(ss, item, ',')) {
data.push_back(std::stod(item));
}
// Assuming the order of data in the CSV matches the fields in BendData
if (data.size() == 4) {
bendData.bendAngleDegrees = data[0];
bendData.insideRadius = data[1];
bendData.materialThickness = data[2];
bendData.kFactor = data[3];
} else {
std::cerr << "Unexpected number of items in line: " << line << std::endl;
}
}
file.close();
}
}