D
drmario
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
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