Re: Comparison with single '='?
On Apr 23, 12:23 am, Old Wolf <oldw...@inspire.net.nz> wrote:
On Apr 20, 12:58 am, Johs <asd...@asd.com> wrote:
#include <iostream.h>
No such standard header, and never has been.
There was when I started using C++. It was, in fact, the de
facto standard up until the promulagation of C++98 (Sept. 1998),
and even some time afterwards, until all of the libraries got
updated. So depending on the date of the book... (Some of the
best and most essential C++ books I have use it, e.g. Barton and
Nackman.)
You can get the
intended effect by putting the following two lines:
#include <iostream>
using namespace std;
That might be sufficient with most implementations, for what
he's doing, but the effect is considerably different. The
standard iostream are NOT compatible with the classic iostream;
there are many subtle differences. And of course, while most
implementations do accept it, as an extension, <iostream>
doesn't declare any of the << operators.
[...]
while (1) {
cout << "Result: " << result << '\n';
cout << "Enter operator and number: ";
Because a '\n' is not sent to the stream, this text may not appear
yet.
Are you sure? C++ doesn't have the concept of a line
synchronized buffer, so the presence or absence of a '\n' is
irrelevant. On the other hand, IIRC, cout is tied to cin, which
means that any input on cin (like that in the following line)
will cause cout to be flushed. (Note that this can cause
reading from cin to be significantly slower than reading from an
ifstream. In non interactive programs, it may be worth
resetting the tie.)
(For the rest, I agree with your evaluation. If the code is
really verbatim out of the book, then it really should be
avoided. Which is rather surprising for O'Reilly.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34