There are advantages and disadvantages to both. printf() is fast =
flexible and usable in c. It has the advantage that the library for =
<stdio.h> is smaller than the equivalent C++ <iostream> so in theory you =
could make smaller apps with it.
However in C++ you can create objects that have stream operators =
associated with them, which allows for a cleaner interfaces most of the =
time. Which makes it easier to output loads of data in an object, i.e =
cout << MyObject; as opposed to printf("Var A: %d, Var B: %s, etc...", =
MyObject.A, MyObject.B, etc...);
In general printf has more in common with other languages such as =
Pascal, and therefore the structured approach. In cout you don't need to =
remember any %letter combinations, as the compiler handles it all for =
you. You can use whatever suits your needs.
In the end the output is directed at STDOUT (or something similar) for =
both.
As for cprintf, does it take the same form as standard printf? It may be =
a dedicated version for a specific implementation, or it only works with =
certain values. I know that standard C does supply a few other printf =
functions i.e. vprintf (I think), but I've never really looked into =
them.
Jason.
----- Original Message -----=20
From: mi...@ju...=20
To: dev...@li...=20
Sent: Tuesday, November 20, 2001 8:36 PM
Subject: [Dev-C++] cout vs cprintf
What's the dif? I'm making a program in AP Computer Science and for =
some reason we used cprintf in it. My "fantatstic" teacher never =
explained why. What gives? Is it a holdover from C?=20
|