June 30th, 2002, 03:46 PM
Difference Between Cout and Printf?
Im new to this forum and kind of new to C++ but i was wondering if there was a "Big" difference between using cout or printf. I allready tried searching with the search button but didnt find a thread about it. Thanks.
cout is an object of the iostream in C++. If you are using C++, then use cout, it works well.
printf while doing some the same things, it is a formatting function that prints to the standard out. This is mainly used in C
On the sidenote, since printf also does extra things there is overhead in speed of using it instead of cout, which simply outputs info.
And you know I mean that.
One more difference is that printf returns an integer value (the number of characters actually printed) and cout does not return anything. Believe it or not, this comes in handy sometimes, especially when you're trying to format your text into columns.
thanks for your replys
Yea its just in that all my books i have it uses cout but in most prgs i see on pscode.com or anywhere else use printf("")
The thing is, that C is still a dominant force in programming, and a lot of C programmer that program in C++ intermix C and C++. Although there are a lot of replacements for functions that are the standard way of doing thing with C in C++ it is still common to see C syntax in C++ programs because that is what most C programmers are comfortable with. It is just a preference.
This is still mainly a console/non-gui application style of programming. Most of the output in gui style applications use neither of these methods. (Although you might see quite a bit of sprintf)