I have one column of floats in a csv file. No column header.
string val;
vector<float> array;
string file = "C:/path/test.csv";
ifstream csv(file);
if (csv.is_open())
{
string line;
getline(csv, line);
while (!csv.eof())
{
getline(csv, val, '\n');
array.push_back(stof(val));
}
csv.close();
}
I want to push the values in the column to vector array
. When I use ','
as a delimiter it pushes the first line to the array but the rest of the column gets stuck together and unpushable. If I use '\n'
it doesn't return the first line and I get a stof
error.
I tried other answers unsuccessfully. What is the correct way to format this here?
test.csv