I have to start with this question:
Is this the ACTUAL content of student.txt?
Student Id = 1200233
Name = Matt
Course = CS
Phone Number = 790-3233
Student Id = 1201237
Name = Benny
Course = IA
Phone Number = 432-4579
Student Id = 1300899
Name = Salma
Course = IB
Phone Number = 790-0000
Student Id = 1502378
Name = Ken
Course = CN
Phone Number = 892-3765
Student Id = 1603679
Name = Sammy
Course = IB
Phone Number = 693-2367
|
If it REALLY is the ACTUAL content, then the line in your most recent code:
in >> num;
Has no "number" to pull in. It would have to be a "5" in that text in order for it to be possible to read that in.
Files of this type do have two basic forms...they might have a definite number at the top. That's a kind of header information, stuff that tells you about the file - in images you may already know that as meta-data.
The other form is just a stream. There is no header, just item after item. For such a file the plan must be to read until there's nothing left to read.
The code must account for that.
So, is the actual file different?
Further, if this is the actual file, what is the plan to deal with the title information?
Consider, this line from the file:
Think. What would come from a read of this line where code says this:
cin >> s;
Where "s" is some kind of string or character array. Do you expect to get the student id number? Do you expect to get the word "Student"?