printf/cout

This is a discussion on printf/cout within the C++ Programming forums, part of the General Programming Boards category; here is the que: Q:-what is the basic difference between cout and printf? i know printf is defined in STDIO.H ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    10

    printf/cout

    here is the que:


    Q:-what is the basic difference between cout and printf?

    i know printf is defined in STDIO.H and cout in IOSTREAM.H.

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Well for starters I believe cout is C++.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    cout is only in C++ because it's a class... there's an entire heirarchy of classes that it derives it's abilities from.

    printf does it's thing without classes.

    basically, if you're programming in C++, use cout. if you're programming in C, use printf. Some people will say printf is faster, and it is marginally faster, but that's not something you should take into consideration.

    cout, being a derived class is more robust, AFAIK.

    take all of the above with a grain of salt - I don't know all that much about printf.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    C++ SharK The SharK's Avatar
    Join Date
    Mar 2004
    Location
    Denmark
    Posts
    62
    Maybe printf is similar to wsprintf, which resides in user32.dll
    Studying programming languages,
    you'll ALWAYS be a student ;-)

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Q:-what is the basic difference between cout and printf?
    The basic difference is that printf is a function and cout is an object. You pass a format string to printf that uses its own little language of format modifiers to tell printf the number and type of things you want to display. cout (usually) does the right thing by figuring out the number and types for you, so it's considered to be safer. Any sophisticated formatting with cout is extremely verbose compared to printf, but that's counter weighted by cout's flexibility. Provided you define the right member functions for your classes, you can use them with cout just like any other object that cout recognizes while it's not so simple with printf. cout, and iostreams in general, are bloated and slower than C-based I/O, but they're far more flexible.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printf/cout
    By Ivan! in forum C++ Programming
    Replies: 4
    Last Post: 03-02-2003, 03:23 PM

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