I have a CSV file that reads something similar to:
1,2,3,4,5
"f[0, 0] + f[0, 1]",5,10,0,2
I realized that the quotations in the CSV file are not exactly "true" to a CSV file; however, this was the format I was given. The function in quotation marks are meant to act as references to the numbers within the CSV file. For example, [0, 0] would mean 1, similar to how a 2D array works. [0, 1] would mean 2, therefore 1 + 2 = 3. I have the evaluation working just fine, I just need a way to parse these lines.
With the code I have right now, it splits the file by comma but when it gets to "f[0, 0] + f[0, 1]", it splits these up into:
"f[0
0] + f[0
1]"
since there are commas.
This is the code I currently have to read in CSV files:
string line;
string field;
vector<vector<string>> v_array;
vector<string> v;
// fills the 2D array up
while (getline(file, line))
{
v.clear(); // clears to add the next line
stringstream ss(line);
while (getline(ss, field, ',')) // this is probably the problem, but idk how to work around it
{
v.push_back(field);
}
v_array.push_back(v);
}
If I run the code I have and parse my CSV file line by line, it would get something similar to:
1
2
3
4
5
"f[1
1] + f[1
2]"
5
10
0
2
Basically if I get everything right, the file would look like:
1,2,3,4,5
3,5,10,0,2