Thread: difference between cout and printf

  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, 06:37 PM
  3. (printf VS cout) and (including libraries)
    By \cFallen in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2003, 09:47 PM
  4. printf and cout
    By master2000 in forum C++ Programming
    Replies: 21
    Last Post: 12-27-2002, 04:32 PM
  5. printf vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 04:26 PM