On Mar 26 22:14, 1997, Mike Walker of 1:153/831.4 wrote:
MW> Hello All!
MW> I know I am probably opening up a big can of worms here. Here goes
MW> anyways. My question has to do with stream output. I know that I
MW> can use the traditional printf for printing formated text. Then
MW> there is the streams (cout) mechanism that I have been reading
MW> about lately. Can someone sum up in a nutshell the
MW> advantages/disadvantages of one method over the other?
Well, I am relatively new to the C++ programming language (more familur with
C), but, I can offer a few. Some of these could be on either side - good or
bad. It depends on what you are trying to do, and what your personal
preferences are.
While the printf() function is generally around two kilobytes in size
(depending on the compiler and such), the cout "operator" is quite small.
The printf() function is much easier to use when trying to output elaborate
(such as columnur) text.
The printf() function requires you to specify *exactly* what you are
outputting, why cout leaves it up to the system to figure out what type of
data you are outputting. (I haven't yet had it go wrong, but ...)
When displaying a date, it would be much easier to use
printf ("Date is %d/%d/19%d\n",month,day,year);
than
cout << "Date is " << month << "/" << day << "/19" << year << "\n";
Right? (Yeah, I know, I should have used %2d to make it more formal, but for
this example, that will do.)
--- TriED 0.10 alpha 1
(1:163/545.15)
---------------
* Origin: World of Power BBS Private Ottawa, Ontario, Canada
|