I want to use getline to read stuff from a file that looks like:
Student ID:88152; Grades: 83.67, 92.45, 74.43, 97.95, 76.45; Name:Abercrombie, Neil
Student ID:92485; Grades: 77.65, 92.31, 60.47, 67.12, 99.64; Name:Aderholt, Robert
Student ID:10623; Grades: 37.95, 83.11, 64.46, 74.76, 95.30; Name:Alexander, Rodney
Student ID:76793; Grades: 53.13, 81.02, 83.71, 90.75, 88.92; Name:Baca, Joe
I have to print to the screen the id numbers, the grades and the names
I'm using getline but im having trouble print out the grades
It gets and displays everything except the grades. One of the grades only gets displayed
Can you tell me what i'm doing wrong?
Edit: It should be a while loop, but im just working with the first line for now
Thank You!
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 35 36 37 38
|
ifstream inf;
char fileName[ MAX_STR_LEN ] = "ex.txt";
char testStr[ MAX_STR_LEN ];
int testInt;
double testDouble;
char dummy;
char comma;
// open file
inf.open( fileName );
// check for good file
if( inf.good() )
{
// get string up to colon, and display
inf.getline( testStr, MAX_STR_LEN, COLON );
cout << "Found garbage: " << testStr << endl << endl;
// get integer value, and display
inf >> testInt;
cout << "Found id number: " << testInt << endl << endl;
inf.getline( testStr, MAX_STR_LEN, COLON );
cout << "Found garbage: " << testStr << endl << endl;
inf >> testDouble;
inf >> comma;
cout << "Found grades: " << testDouble << endl << endl;
inf.getline( testStr, MAX_STR_LEN, COLON );
cout << "Found more garbage: " << testStr << endl << endl;
// get next line string, and display
inf.getline( testStr, MAX_STR_LEN, ENDLINE_CHAR );
cout << "Found name: " << testStr << endl << endl;
}
|