I am trying yo read in text from a file that is formatted like this:
Carrier,E6,H
Battleship,E7,H
Cruiser,E8,H
Submarine,E9,H
Destroyer,E10,H
Currently my last line is reading twice. I have tried using while(!infile.eof) and (infile >> name) with similar results. My current output is:
Carrier E6 H
Battleship E7 H
Cruiser E8 H
Submarine E9 H
Destroyer E10 H
E10 H
ifstream infile;
infile.open("ships.csv");
while(infile.good()){
getline(infile, name, ',');
cout << name << " ";
getline(infile, location, ',');
cout << location << " ";
getline(infile, orientation);
cout << orientation << endl;
Aucun commentaire:
Enregistrer un commentaire