reading till end of file problems

I have been working on this program for a couple of days now and I still cant seem to get it to do what I want it to do.
I am using fin.peek() to read character from input file and saving each character into an array.
each line from the input has first name, last name, id number, and then 5-6 grades. Random spacing between each one.

input file example:
Adam Zeller 45678 80 87 60 90 88 100
David Young 34521 34 56 76 76 76 76
Carl Wilson 909034 90 90 90 49 39

my code for reading in and storing each character is this:

while(fin.peek() == ' ')
fin.get();

while(fin.peek() != ' ') ///// first name
{
c = fin.get();
first[i] = c;
first[i+1] = '\0';
i++;
}

cout << first << endl;

while(fin.peek() == ' ')
fin.get();

i = 0;
while(fin.peek() != ' ') /////// last name
{
c = fin.get();
last[i] = c;
last[i+1] = '\0';
i++;
}

cout << last << endl;

while(fin.peek() == ' ')
fin.get();

i = 0;
while(fin.peek() != ' ')//////////////////// ID
{
c = fin.get();
iD[i] = c;
iD[i+1] = '\0';
i++;
}
cout << iD << endl;

while(again == true)//////////// grades
{
again = false;
while(fin.peek() == ' ')
fin.get();

if(fin.peek() == '-')// Checks for negative number error.
{
cout << "***Error, negative grades not allowed!***";
return -1;
}
if(isdigit(fin.peek()))// record grade
{
fin >> score;
//cout << "inside if loop isdigit: " << score<< endl;
again = true;
}

if(again == true) // place grade in array
{
cout << score << endl;
scoreArray[testNumb] = atof(score);
testNumb++;
}
}

The problem I am having is what sort of loop would go around this to read till end of file. I have tried eof. I have tried while(!fin.peek == \n') and I have tried a couple of other methods. these methods resulted in a never ending loop execution. So now I feel stuck. Any suggestions or hits to lead me in the right directions would be greatly appreciated! Thank you.
I don't really understand your code but
if your file has pattern like you said above
which is 2 strings and 7 integers per line

then I suggest you do this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

struct data_t {
    string name;
    string famname;
    int one;
    int two;
    int three;
    int four;
    int five;
    int six;
    int seven;
};

int main ()
{
    ifstream in("filename.txt");

    data_t temp;
    vector< data_t > datas;

    while( in >> temp.name >> temp.famname >> temp.one >> temp.two >> temp.three >> temp.four >> temp.five >> temp.six >> temp.seven ){
        datas.push_back( temp );
    }

    for( int i = 0; i < datas.size(); ++ i){
        cout << datas[i].name << endl;
    }
}


Well this code might cause problem is the data is not as specified
for instance,
Carl Wilson 909034 90 90 90 49 39

This one have 2 strings and 6 integers

This line will skipped
Topic archived. No new replies allowed.