Check my logic? (average gpa calculating program)?

Wouldn't these lines: skip every other line: while( inData >> gender >> gpa ) { inData >> gender >> gpa You're using the return of the >> operator to indicate success for the test of the while loop, but each time it executes that, does it not consume that line and move to the next, so then when you execute it again inside the while loop you effectively overwrite the data from line 1 with the data from line 2 and ignore line 1.

Wouldn't these lines: skip every other line: while( inData >> gender >> gpa ) { inData >> gender >> gpa; You're using the return of the >> operator to indicate success for the test of the while loop, but each time it executes that, does it not consume that line and move to the next, so then when you execute it again inside the while loop you effectively overwrite the data from line 1 with the data from line 2 and ignore line 1.

Bingo, took it out and it works like a charm. Thanks a lot – mwmnj Dec 19 '10 at 2:37 That what I used initially but this other way was suggested to me as being better. See the answer to my previous post: stackoverflow.Com/questions/4479504/first-fstream-program/… – mwmnj Dec 19 '10 at 2:48 Okay, I did some more research and I guess what happens is that the ifstream is cast to a pointer when used as the test in a while loop, if the failbit is set (which occurs when you attempt to read past EOF) it returns null which is the same as false.

So yes, that usage is fine. – Paul Wheeler Dec 19 '10 at 4:03 Oh and this site: cplusplus.Com/reference/iostream/ifstream is great, BTW. – Paul Wheeler Dec 19 '10 at 4:05 1 I wish we could -1 comments at times like this.

If (stream >> foo) (and similarly with 'while') is not only fine and designed for, but idiomatic. Testing while (!stream.eof()) is, in most cases, exactly what you don't want to do, because .eof() doesn't return true until after there has been a failed attempt - the practical result, in most cases, is that you process the last item twice. See parashift.

Com/c++-faq-lite/input-output. Html#faq-15.4 for more. – Karl Knechtel Dec 19 '10 at 4:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions