View Poll Results: printf vs. cout

Voters
26. You may not vote on this poll
  • cout

    13 50.00%
  • printf

    13 50.00%

Thread: printf vs. cout!

  1. #1
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269

    printf vs. cout!

    Personally, I like cout. What do you guys think?

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    I actually learned C++ before I learned C, so I prefer cout.

    However, I have heard the printf is slightly faster. I am not sure if this is true or not, but it is what I have heard.

    Still, cout is quite nice. A quick overload of the << operator can make it output pretty much anything. It is pretty nice.

    I think if you are programming console, it doesnt really matter which you use. Not many people care about the miniscule difference in how fast text is outputted in console mode.

    cout is not used very much in GUI programming, although I do use fstream's quite a lot. fstreams are VERY nice things to have. I love them.
    My Website

    "Circular logic is good because it is."

  3. #3
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    I like printf..... because it's the only one I ever learned. I've taken 3 C classes and have never messed with C++ so far.

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    cout is more like javascript. I like c's % thingy much more control and easier to output.

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >I like c's % thingy much more control and easier to output

    Agreed. And if you wish you can apply this style formatting to buffer output if you are using a text setup that isn't the console (ie a graphics setup, that's what I used in AktiF). Though it takes a bit of work, it's worth this rather than redefining formatting yourself.
    hasafraggin shizigishin oppashigger...

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Gee, this hasn't been done before
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    cout or printf? None.

    I like sprintf best cout & printf ain't cool for GUIs.

  8. #8
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    when I do console stuff, I prefer printf, in fact, I always use C's stdio instead of C++'s iostream.

  9. #9
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    cout has nifty type-checking. and you can define it for use with new objects you create, like string objects. anything you can do with printf can be done with cout using manipulators.

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I use cout because I don't know how to use printf... it looks like you can have more control over it, which would appeal to me if I actually bothered to learn how to use it...
    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

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Hey is there any equivalent for sprintf() under C++?

  12. #12
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by DavidP
    However, I have heard the printf is slightly faster. I am not sure if this is true or not, but it is what I have heard.
    No, cout is faster than printf because cout has compile-time type-checking whereas printf has to parse a string.
    Originally posted by DavidP
    Hey is there any equivalent for sprintf() under C++?
    std::stringstream in <sstream>
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  13. #13
    >>No, cout is faster than printf because cout has compile-time type-checking whereas printf has to parse a string.
    didn't Sunlight proved that it's the other way around, or is my memory playing tricks on me?

  14. #14
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    printf is faster than cout. You can try measuring the execution time between there and you'll see the big discrepancy, in favor of printf. cout sucks.

  15. #15
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I don't know how to use printf. All those %'s and whatever, I can't keep em straight.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  3. Need Help with a Bowling Score Program
    By oobootsy1 in forum C++ Programming
    Replies: 6
    Last Post: 11-01-2005, 10:04 AM
  4. Whats Wrong Whith This!?
    By SmokingMonkey in forum C++ Programming
    Replies: 8
    Last Post: 06-01-2003, 09:42 PM
  5. (printf VS cout) and (including libraries)
    By \cFallen in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2003, 09:47 PM