Thread: cout or printf?

  1. #1
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605

    cout or printf?

    which is better to use?
    .

  2. #2
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    If your trying to adhere to standard C++, the choice is obvious.

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    printf is still covered by the C++ standard. I like streams type safety (never forget the formatter) and extensibility (can use directly with own classes), but printf has more terse sematics (for example, limiting number of decimal places with output).
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  4. #4
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    printf is still covered by the C++ standard.
    Wow, I didn't know that. Ya see you learn something new here everyday.

    Why do you often hear people say that using printf is a mix of C and C++ and should not be done? Because I have had several people here tell me that.

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I don't see anything wrong with mixing C and C++. C++ was designed with backward compatibility for a reason. If you are gonna take all the bad parts of C, you may as well take advantage of the good parts as well.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  6. #6
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001

    definetely

    I agree 100% with silent strike.
    I don't know where I'd by without the c string functions (ie: strcat, strtok, strcpy, etc.)
    I use c functions all the time right beside C++, i think people who strictly adhere to one or the other are severly limiting themselves in the power and versatility of their programs, as well as their creativity.
    PHP and XML
    Let's talk about SAX

  7. #7
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    adhering to c++ allows (read: forces) you to use c++'s object-oriented features. it can help where c might bog you down to its lowest denominator. ie:
    Code:
    string temp;
    temp = "string";
    cout << string << setw(5) << string << endl;
    printf("%s\n",string.c_str());
    the first three statements are somewhat encapsulated. the details are somewhat hidden. when you reach printf, which knows nothing about classes, you must use a special function of the string class to maintain compatability.

    i'm not against using both at once. c++ was built for backwards-compatability. i just believe that object-oriented programming works best when the objects interact without the C functions that are unaware of classes.

  8. #8
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    ok thanks alot for your gelp, guys!
    .

  9. #9
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    ok thanks for your help!
    .

  10. #10
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    yes but i here that you should try to use c++ functions and were you need to do somethign like strlen, use it.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >which is better to use?
    My rule of thumb is to use the iostream with C++ and the stdio with C.

    -Prelude
    My best code is written with the delete key.

  12. #12
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Just don't use both. It can lead to some weird problems.

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