1

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

  1. ........5................0
  2. .......0.................0
  3. .......3................33
  4. .......4................50
  5. .......6................0
  6. .........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;
daf3131
  • 25
  • 2
  • 1
    BTW, parsing a CSV file has nothing to do with Excel; the file could have been generated by any number of applications. Suggest removal of `excel` tag. – Thomas Matthews Apr 24 '16 at 21:38
  • Have you searched the internet for ["c++ read file csv"](https://www.google.com/search?q=c%2B%2B+read+file+csv&ie=utf-8&oe=utf-8)? There are a lot of examples to study. – Thomas Matthews Apr 24 '16 at 21:39
  • Maybe this [question](http://stackoverflow.com/questions/1120140/how-can-i-read-and-parse-csv-files-in-c) will help you – al0011 Apr 24 '16 at 21:44

0 Answers0