#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13

    Difference Between Cout and Printf?


    Hi everyone,

    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.

    -Optix
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    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
  4. #3
  5. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    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.
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    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("")
  10. #6
  11. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    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)

IMN logo majestic logo threadwatch logo seochat tools logo