Click here to Skip to main content
16,004,901 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CFileFind Pin
Stephen Hewitt30-Oct-06 14:19
Stephen Hewitt30-Oct-06 14:19 
GeneralRe: CFileFind Pin
Stephen Hewitt30-Oct-06 14:26
Stephen Hewitt30-Oct-06 14:26 
QuestionExcel Page Pin
roadme25-Oct-06 11:26
roadme25-Oct-06 11:26 
AnswerRe: Excel Page Pin
freeman86825-Oct-06 16:59
freeman86825-Oct-06 16:59 
GeneralRe: Excel Page [modified] Pin
freeman86825-Oct-06 17:01
freeman86825-Oct-06 17:01 
GeneralRe: Excel Page Pin
roadme27-Oct-06 8:42
roadme27-Oct-06 8:42 
GeneralRe: Excel Page Pin
roadme27-Oct-06 9:00
roadme27-Oct-06 9:00 
QuestionReading from File question... [modified] Pin
q_p25-Oct-06 11:20
q_p25-Oct-06 11:20 
Hello. I'm new to C++ so go easy. I'm trying to read from a txt file, but need to do it in a specific way. The txt file will basically be formatted like this:
1111 90 85 50 78 85
2222 100 90 99 89 88
3333 52 85 44 66 87
4444 87 88 95 85 100

where the first number of each line will be a student ID number and the next five numbers are grades they got on 5 different tests. I need to read this file as such and then do stuff with that data. What I don't know is how to read the file and store those numbers in a usable way. The thing is I don't know how many lines the file will have, so I need go all the way to the end of the file. Given this, do I have to create an array for the different inputs from the file, and how do I then differentiate between the student ID numbers and the test grades?

What I have so far is laughable because I simply don't know how to go about this, but here it is:

int id, score1, score2, score3, score4, score5;<br />
ifstream inFile;<br />
inFile.open ("grade.txt", ios::in);<br />
while (!inFile.eof())<br />
{<br />
    inFile >> id >> score1 >> score2 >> score3 >> score4 >> score5;<br />
}<br />
inFile.close();


Obviously the while loop isn't done yet because I don't know what to do after I have a line of input from the file. Any help would be awesome.


-- modified at 17:27 Wednesday 25th October, 2006
AnswerRe: Reading from File question... Pin
led mike25-Oct-06 11:34
led mike25-Oct-06 11:34 
GeneralRe: Reading from File question... Pin
q_p25-Oct-06 11:40
q_p25-Oct-06 11:40 
GeneralRe: Reading from File question... Pin
Zac Howland25-Oct-06 11:47
Zac Howland25-Oct-06 11:47 
GeneralRe: Reading from File question... Pin
led mike25-Oct-06 11:49
led mike25-Oct-06 11:49 
AnswerRe: Reading from File question... Pin
Zac Howland25-Oct-06 11:45
Zac Howland25-Oct-06 11:45 
GeneralRe: Reading from File question... Pin
led mike25-Oct-06 12:01
led mike25-Oct-06 12:01 
GeneralRe: Reading from File question... Pin
Zac Howland25-Oct-06 12:53
Zac Howland25-Oct-06 12:53 
GeneralRe: Reading from File question... Pin
q_p25-Oct-06 12:16
q_p25-Oct-06 12:16 
GeneralRe: Reading from File question... Pin
Zac Howland25-Oct-06 12:55
Zac Howland25-Oct-06 12:55 
GeneralRe: Reading from File question... Pin
ThatsAlok25-Oct-06 20:57
ThatsAlok25-Oct-06 20:57 
GeneralRe: Reading from File question... Pin
Stephen Hewitt25-Oct-06 15:12
Stephen Hewitt25-Oct-06 15:12 
GeneralRe: Reading from File question... Pin
Zac Howland26-Oct-06 3:59
Zac Howland26-Oct-06 3:59 
GeneralRe: Reading from File question... Pin
ThatsAlok25-Oct-06 20:51
ThatsAlok25-Oct-06 20:51 
GeneralRe: Reading from File question... Pin
Zac Howland26-Oct-06 4:03
Zac Howland26-Oct-06 4:03 
QuestionRe: Reading from File question... Pin
David Crow26-Oct-06 4:34
David Crow26-Oct-06 4:34 
AnswerRe: Reading from File question... Pin
Zac Howland26-Oct-06 4:51
Zac Howland26-Oct-06 4:51 
GeneralRe: Reading from File question... Pin
David Crow26-Oct-06 5:02
David Crow26-Oct-06 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.