MW>Hello All!
MW>I know I am probably opening up a big can of worms here. Here goes
anyways. My
MW>question has to do with stream output. I know that I can use the
traditional
MW>printf for printing formated text. Then there is the streams (cout)
mechanism
MW>that I have been reading about lately. Can someone sum up in a nutshell
he
MW>advantages/disadvantages of one method over the other?
Mike - Let me offer a few advantages of stream I/O
1. The same symbols (">") or function names are used to read
from, or write to any kind of device (console, file, or in-core
storage). With stdio, you have to remember to use printf, sprintf, or
fprintf depending on what kind of device you are writing to.
2. Stream I/O is extensible, standard I/O is not. For example, you can
write your own operator "<<" to write the contents of an instance of
a structure; you cannot reasonably modify printf() to write the
contents in the same manner.
3. Stream I/O is parsed at compile time, stdio is parsed at run time.
This means that stream I/O can potentially be smaller and faster than
stdio. (Note that I said potentially; The efficiency of stream I/O
and stdio depends on the compiler writer)
4. If you're willing to derive objects from streambuf and iostream, you
can build your own devices (perhaps a "modem" or an "ascii display")
that work the same way as the standard stream devices (cin, cout,
fstreams or strstreams). You can't really do that with stdio.
Other than being able to work with legacy programs written in C, (There,
I was finally able to use the term "legacy" in connection with C and C++
:), I can't think of any inherent advantage of stdio over stream I/O.
-- Jerry
---
* OLXWin 1.00b * CALCULUS...the agony and dx/dt
--- InterEcho 1.19
---------------
* Origin: PC-Ohio PCBoard * Cleveland, OH * 216-381-3320 (1:157/200)
|