Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Filestream inpu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 44104 of 47561
Post > Topic >>

Filestream input kickin my arse

by "drmario" <drmario@[EMAIL PROTECTED] > Mar 25, 2008 at 05:09 AM

I normally hate asking for help when I feel like I should be able to get 
something on my own.  But after about 10 hours of trying to figure out
where 
I'm going wrong, I have to surrender.

I need to open a file and read the data in.  It will be in this format:

Gali leo                     100.0
Michael Angelo           100.00
Mario Hollibaugh        99.4
Christopher Polites     92.7
Rodney Monson         100
Michael Jordan             74.28
Bill Gates                     95
Joanof Arc                 89.6
How Now                 94
Dane Cook                 98.8

It's supposed to be first name, last name, test score.  The only thing 
guaranteed about the format is that it will be:

(x)firstname(x)lastname(x)grade(x)

where x=any possible number of spaces or tabs.  I'm not allowed to use 
getline, and I can't use the datatype string.  I have to read the first
and 
last name as cstrings, and then read the grade in as double.  If the
person 
who builds the text file puts in an entry like:

95 Angelo 100.00

well then that's their fault and the output will list 95 as Angelo's first

name.  However, if they make such an entry:

Michael Angelo b

he simply ends up without a grade recorded.

The general algorithm I'm using is: (I will omit EOF checks for
simplicity's 
purpose)
1)  If leading whitespace exists: (if ifstream.peek()==' ' || 
ifstream.peek()=="\t")
        use ifstream.get to read it into a junk char var
2)  Once first char of first name is found
        use ifstream.get to read the chars of the first name, one by one, 
into a string var
3)  Once last char of first name is found
        insert ' ' after first name using simple assignment
repeat all that for last name
4)  a simlple ifstream >> to read the grade into double variable (which 
should ignore all whitespace)
5)  Check if ifstream is good with if(!ifstream), in other words check if 
the user was a moron and can't follow formatting instructions.  If not, 
clear the stream.
6)  Ignore all characters (using numeric limits) until I reach the '\n' 
character.
7)  Repeat on next line

It's working perfectly for the first line, but for some reason it messes
up 
after that.  Furthermore, when I put a cout << test inside my
if(!ifstream), 
it gets printed up on the screen a dozen times.  I can't understand why. 
Nothing in my sample file should be causing input failure.

If I haven't bored you to death, any suggestions? :-)  Thanks guys!

cheers,
Mario
 




 6 Posts in Topic:
Filestream input kickin my arse
"drmario" <d  2008-03-25 05:09:32 
Re: Filestream input kickin my arse
Michael.Boehnisch@[EMAIL   2008-03-25 08:39:35 
Re: Filestream input kickin my arse
"drmario" <d  2008-03-25 12:08:47 
Re: Filestream input kickin my arse
James Kanze <james.kan  2008-03-26 03:02:58 
Re: Filestream input kickin my arse
"drmario" <d  2008-03-26 14:19:45 
Re: Filestream input kickin my arse
James Kanze <james.kan  2008-03-26 14:53:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 4:10:46 CDT 2008.