0 vs. "0"greenspun.com : LUSENET : Steve Heller's books : One Thread
In the implementation of operator >>, after the variables are read in, you have:if (Expires == "0")which of course checks if this worker is a dated or undated object. However, in the undated object code (which would output the 0), the Write(ostream& os) function has:os<<0<<endl;I was expecting that either
1. the write function would output "0" or
2. the >> operator would check for 0 instead of "0", to maintain the same syntax.
What don't I know here? I'm missing something.
-- Mike Mannakee (B3FEETBACK@AOL.com), May 09, 1999
The write function writes the ascii code for a 0 character out, as one of its purposes is to converts values to ascii format for display. The if statement, on the other hand, is comparing the value of the string Expires to a literal "0"; if you changed that statement to say:if (Expires == 0)that would try to compare the string Expires to the number 0. I don't think that would compile, but if it did it wouldn't work.
-- Steve Heller (firstname.lastname@example.org), May 09, 1999.