file is not being read correctly

I need to read in grade data from a file, but right now I cannot get the grades read in.

The student name and class name is read in, but then the grades are not and I cannot figure out why the program stops reading the file


The file I am trying to read from is the following

1
2
3
4
5
6
7
8
9
10
11
5
Smith, John
Computer Science 70 75 80 75 90 100 50 96 76
White, Joe
Biology 83 56 86 90 84
Brown, Marvin
Theater 75 80 72
Scoop, Milly
Computer Science 45 57 26 79 54 52 74 60 45
Can, Homer 
Theater 82 78 85
Last edited on
where are your headers?
headers for what
Your program requires several header files to be included in order to compile. For example you should have a line #include <iostream> in order to use the console input and output streams cin and cout.

Look at the following snippet:
1
2
    
   Base** List = new Base*[numStudents]; //allocate space for array of students 


What is a Base? Where is it defined?

Next since your class name can have spaces you'll need to insure that you remove the entire name from the file before you start extracting the numbers. This is probably what is causing you problems right now. It appears that you're only extracting the first part of a multiple word class name. You would be better off reading this entire line with getline, then processing the line with a stringstream, this will prevent causing errors in your file stream, which is probably what is happening now.






you need
<iostream>
<fstream>
<string>

using something like
string filename; /* then do this after the cout:*/ cin >> filename;

Also before starting anything make sure the file you want opens. Don't just start writing code.
Note make sure wherever you are saving your .cpp file is the same place as the file that you want to open.
Both files are opening, and the class name and student name is being read, but the grades are not being read, I do not know why the integers are not being read
Both files are opening, and the class name and student name is being read,

No, the class name is not being properly read. You only read one word of multi-word class names. This is the problem. You need to read the entire name, not just part of it.

Both files are opening,


How do you know this, you never check that the files opened properly. You should always check that the files properly opened and tell the user if they don't.
Last edited on
I removed the error checking to save space, both files work

Last edited on
Topic archived. No new replies allowed.