D
drmario
I'm using VC++ 8.0 Express Edition on Windows XP Home Edition. I've
opened a file with ifstream:pen(). The text in the file will have the
general format of:
michael jordan 90
roger moore 79
your name 100
So basically a first name, last name, grade, \n. I'm using
ifstream::get() to one by one read each char of the first and last name into
a cstring (no not string data type. An array of chars. I suppose
technically an array of pointers to chars). Then I use ifstream >> to read
the grade. It's kinda a long story why, but this is the (inefficient, I
know) way I've chosen to do it and I'm not going to change it.
Taking James Kanze's previous advice I inserted a buncha statements to
check the stream's error state flags after every input. I discovered that
after I read the last student's grade using ifstream >>, the program sets my
stream's eofbit to true. This of course makes sense. What does NOT make
sense to me is this after every iteration of reading a line, and echoing it
to the screen, my program reaches the getch() statement, and correctly
pauses until I hit a key then continues on. However, on its last iteration,
after it's read the very last thing in the text file and the eofbit is set
to true, I have to push like three or four keys.
Why is that happening? It makes 100% no sense to me. Why does the fact
that my ifstream's eofbit is set to true cause getch() to misbehave?
getch() has one job... wait until the next key is hit and return that value.
Why is this stupid ass ifstream::eofbit making it jack up? From my
understanding getch() doesn't even acknowledg the existence of a friggin
file stream, only the standard input stream.
Yes, as I'm sure you can tell, it pisses me off when Microsoft decides
not to include every detail of the inner workings of their STL
functionality. You'd think if there was anyone who could appreciate the
occasional need for subtle detials it would be the guys writing compilers.
Anyone I'm done venting. I hope someone can shed some light on why
getch() suddenly misbehaves after the eofbit is set to true. I'm stuck
fast, and have been so for weeks.
cheers,
Mario
opened a file with ifstream:pen(). The text in the file will have the
general format of:
michael jordan 90
roger moore 79
your name 100
So basically a first name, last name, grade, \n. I'm using
ifstream::get() to one by one read each char of the first and last name into
a cstring (no not string data type. An array of chars. I suppose
technically an array of pointers to chars). Then I use ifstream >> to read
the grade. It's kinda a long story why, but this is the (inefficient, I
know) way I've chosen to do it and I'm not going to change it.
Taking James Kanze's previous advice I inserted a buncha statements to
check the stream's error state flags after every input. I discovered that
after I read the last student's grade using ifstream >>, the program sets my
stream's eofbit to true. This of course makes sense. What does NOT make
sense to me is this after every iteration of reading a line, and echoing it
to the screen, my program reaches the getch() statement, and correctly
pauses until I hit a key then continues on. However, on its last iteration,
after it's read the very last thing in the text file and the eofbit is set
to true, I have to push like three or four keys.
Why is that happening? It makes 100% no sense to me. Why does the fact
that my ifstream's eofbit is set to true cause getch() to misbehave?
getch() has one job... wait until the next key is hit and return that value.
Why is this stupid ass ifstream::eofbit making it jack up? From my
understanding getch() doesn't even acknowledg the existence of a friggin
file stream, only the standard input stream.
Yes, as I'm sure you can tell, it pisses me off when Microsoft decides
not to include every detail of the inner workings of their STL
functionality. You'd think if there was anyone who could appreciate the
occasional need for subtle detials it would be the guys writing compilers.
Anyone I'm done venting. I hope someone can shed some light on why
getch() suddenly misbehaves after the eofbit is set to true. I'm stuck
fast, and have been so for weeks.
cheers,
Mario