In the following code I want to validate some data. However, I have no clue how to do this with a csv file comma delimiter. If I wanted to replace the vectors vector submitted{5,0,3,4,6,1} and vector expected{0,0,33,50,0,0} with a vector from a csv file with two columns like this:
........submitted....expected
- ........5................0
- .......0.................0
- .......3................33
- .......4................50
- .......6................0
- .........1............0
so basically i want to get my vector from a csv file... where column submitted is my first vector and expected column is my second vector. I want to work with more data and place it in my csv file and then convert it into a vector and replace the submitted and expected from the code below to a vector with a vector from my csv file. is there any way to do this?
int main() {
vector<int> result;
vector <string> validate;
vector<int> submitted{5,0,3,4,6,1};
vector<int> expected{0,0,33,50,0,0};
for (int j = 0; j < submitted.size(); j++) {
for (int i = 0; i <= submitted[j]; i++) {
if (round(((1.0 / submitted[j]) * i) * 100) == expected[j]) {
validate.push_back("passed");
result.push_back(round(((1.0 / submitted[j]) * i) * 100));
cout << " Result: " << result[j]<<" Expected : " << expected[j]<< " Status: "<< validate[j]<<endl;
break;
}
//if the next greater number than expected, give the last plausible integer
else if (round(((1.0 / submitted[j]) * (i+1)) * 100) > expected[j]&&expected[j]!=0&&submitted[j]!=0) {
validate.push_back("failed");
result.push_back(round(((1.0 / submitted[j]) * i) * 100));
cout << " Result: " << result[j] << " Expected : " << expected[j] << " Status: " << validate[j]<<endl;
break;
}
else if (expected[j] == 0||submitted[j]==0) {
validate.push_back("failed");
result.push_back(0);
cout << " Result: " << 0 << " Expected : " << 0 << " Status: " << " passed " << endl;
break;
}
}
}
return 0;