-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadcsv.cpp
More file actions
39 lines (35 loc) · 907 Bytes
/
loadcsv.cpp
File metadata and controls
39 lines (35 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Created by dhruva on 4/9/25.
//
#include <fstream>
#include <sstream>
#include "loadcsv.h"
#include <iostream>
std::vector<DataPoint> loadCSV()
{
std::vector<DataPoint> datapoints;
std::string line;
std::ifstream file("datapoints.csv");
if (file.is_open())
{
while (std::getline(file, line))
{
std::stringstream ss(line);
std::string label;
std::getline(ss, label, ',');
std::vector<float> features;
std::string feature;
while (std::getline(ss, feature, ','))
{
features.push_back(std::stof(feature));
}
auto datapoint = new DataPoint(features, label);
datapoints.push_back(*datapoint);
}
} else
{
std::cerr << "Could not open the file!" << std::endl;
}
file.close();
return datapoints;
}