Mail Archives: djgpp/1998/10/08/18:44:34
Okay, I'm a programmer by trade and have had *some* experience with C
and C++, but I've mostly known BASIC. Now I'm teaching myself C++
from one of the Waite Group's books ("C++ Primer Plus").
I'm not sure what version of DJGPP I've got (I d/l and set up the
compiler earlier this year) but the compile output says GNU version
2.8.1.
Anyway, here's my problem: I'm writing a utility that will read
through a text document (specifically, an HTML document), find all the
link tags, and output a list of urls. After writing and debugging the
functions, I moved them all into a class structure (I'm so proud- my
first class :-). Everything was working fine- I was using cin and
cout to handle I/O and redirection at the command line ( exe >
outputfile < inputfile). Then I tackled actual file I/O....
To make sure I have the concepts down (as I read my book), I started
by writing the list of urls to an output file. This worked fine.
Then I went back to cout- so I could see the output on the screen.
Next, I dove into file input:
I declared an input object (this is in the private section of the
class),
ifstream fin;
pointed it to a filename (this is done in the constructor),
fin.open(filename);
and started reading the file in. Here's where I have the problem:
bool html_parse::findtag() {
char ch;
while(!fin.eof()) {
fin.get(ch);
if (ch == '<') {
return(true);
}
}
return(false);
}
Since I can't step through the code, I've set up cerr outputs to tell
me what the value of fin.eof() is. Immediately before fin.get(ch),
the value of the eofbit is false, but immediately after, it is true.
This, of course results in only the first character being read in and
then the program aborting (it *is* getting the correct character, I've
checked that).
Why is the eofbit being set? What am I missing here? As I said, this
exact code worked fine when I was using cin instead of fin- all I did
was a search and replace, replacing all instances of cin with fin.
I'd appreciate any advice or insight anybody could offer.
- Shawn
- Raw text -