difference between cout and printf

This is a discussion on difference between cout and printf within the C++ Programming forums, part of the General Programming Boards category; so let me get this straight you can use cout or printf to output text to the screen right?? right? ...

  1. #1
    Shadow12345
    Guest

    difference between cout and printf

    so let me get this straight you can use cout or printf to output text to the screen right?? right?
    also you must include stdlib to use printf correct?
    You see I thought printf was primarily used for visual cpp, but i noticed someone who used in it one of their programs so I am kinda confused and I would appreciate it if you could explain the differences between the two.

    ok thanks in advanced

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    printf() doesn't type check, cout does.

    some people prefer printf()'s formatting over ostream's manipulators/flags/etc, ; other's disagree.

    printf() is C style output, cout is C++ style output

    C++ allows both printf() and cout to be used

    C only allows printf().

    include stdlib.h for printf()

    include iostream.h or fstream.h (drop the .h if you have an up to date compiler) for cout.

    as a general rule, it's not considered wise to mix printf() and cout in the same program.

    Use whichever you want.
    Last edited by elad; 04-29-2002 at 08:34 AM.

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    You only need to include the stdio library to use printf.

    As elad mentioned, C programmers use printf, C++ programmers get to choose but usually use cout. If you mix the two in the same program it can result in massive headaches.
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cout to printf problems
    By hallo007 in forum C++ Programming
    Replies: 9
    Last Post: 09-27-2006, 10:22 AM
  2. how to do printf( "%c", 12 ); via ostream cout ??
    By L.O.K. in forum C++ Programming
    Replies: 9
    Last Post: 01-08-2005, 05:37 PM
  3. (printf VS cout) and (including libraries)
    By \cFallen in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2003, 08:47 PM
  4. printf and cout
    By master2000 in forum C++ Programming
    Replies: 21
    Last Post: 12-27-2002, 03:32 PM
  5. printf vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21