0

So this is giving me my desired output except that the last line print twice (minus the name).It is repeating data at the end that is not present in the small little excel sheet. Is there anything obvious in my code, i am guessing my While loop, that would be causing it to do this? Thank you!

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main() {
    // declare variables
    ifstream inFile;
    string name, age, dec, ch, extra;

    // open file
    inFile.open("C:/Users/Joe/Downloads/input.csv");

    //create loop that stops when entire file is read
    while (!inFile.eof()) {


        //collects all data up to a ',' and then stores that data in the respective variable
        getline(inFile, name, '\,');
        getline(inFile, age, '\,');
        getline(inFile, dec, '\,');
        getline(inFile, ch, '\,');
        getline(inFile, extra);




        cout << left;
        cout << setw(8) << name
            << setw(8) << age
            << setw(10) << dec
            << setw(5) << ch
            << setw(5) << extra
            << endl;


    }


    // closes the file
    inFile.close();
    //pause and exit
    getchar();
    getchar();
    return 0;
}
Catz
  • 11
  • 5
  • 4
    Related: [Why is iostream::eof inside a loop condition considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – Algirdas Preidžius Jan 26 '18 at 19:19
  • 1
    @AlgirdasPreidžius I'd call it a dupe. Looks like the reason for the issue OP is having. – scohe001 Jan 26 '18 at 19:20

0 Answers0