I'm making a program for class that requires me to read a text file that has grades and names. I'm using string variables for names, and I've gotten my code to work for the first 2 lines in the text file but there are an uneven amount of grades for each person and it's kinda throwing me off as to what I should be doing. I tried a few different 'while' loops but so far the 'for' loops have given me the most accurate result, but still not what I'm looking for.
Here's what I have so far:
#include "stdafx.h"
#include"windows.h"
#include"iostream"
#include"fstream"
#include"iomanip"
#include"string"
#include"math.h"
#include"conio.h"
#include"time.h"
#include"cstdio"
using namespace std;
string name, score2, score3, score4, score5, score6;
char score1;
double numcount;
int main()
{
cout << "GPA\n\n";
ifstream get;
get.open("GPAS.txt");
while (!get.eof())
{
get >> name;
cout << name;
get >> name;
cout << " " << name << endl;
for (numcount = 0; numcount < 7; numcount ++)
{
get >> score1;
cout << score1 << "\t";
}
}
get.close();
system("pause");
return 0;
}
The text file just contains this
John Doe A B A C B A *
Mary Jones B A A C *
Henry Ford C C C C C C *
Betsy Ross A A A B B *
Jack Sparrow B B B *
Elizabeth Swann A A *
Edit: So apparently 'eof' is extremely frowned upon; however, in class we've sort of just learned how to use this, so naturally we're supposed to incorporate it into the code. Also, the question asked that had been answered didn't answer my question. The loop works fine, it's the innards of the loop that aren't coming out at all correctly formatted. Also, reading until '*' was how I was doing it previously, but it was working less proper than it is with the 'for' loop.