View Poll Results: Which is is better

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

    26 45.61%
  • printf()

    24 42.11%
  • Either

    7 12.28%
  • Neither

    0 0%

Which one will you prefer: cout or printf

This is a discussion on Which one will you prefer: cout or printf within the A Brief History of Cprogramming.com forums, part of the Community Boards category; this is a very common poll, however, i must say i always use both, but i like more printf, BUT ...

  1. #16
    Registered User
    Join Date
    Dec 2001
    Posts
    21
    this is a very common poll, however, i must say i always use both, but i like more printf, BUT cin is MUCH better than scanf. scanf really ........es me off. but i really like printf!...

  2. #17
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    I think printf() is faster. I vaguely (very very very vaguely) remembered a discusion on the old board. and I think it was Sunlight who wrote a program to test it and printf() was faster.
    You are correct. I recall Sunlight getting quite upset on the subject... Not that it was an unusual state for him or anything. ... RANT: system(), cout, goto, DOS... you name it.

    Printf is faster than cout by a fair margin. I dont use either now though as i've only created DirectX Apps lately.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #18
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    >>sprintf() Might be the same, I never used it

    sprintf just copies on string over another...I wouldn't say it's faster thanprintf() because it does something totally different

    Yeah, I :VERY: vaguely recall that...I use printf() when I do C/C+ DOS/Console stuff, anyhow so I didn't really care. I learned printf() first...ah, how I miss those late nights enthralled in C For Dummies .

    But I'm with lightatdawn. I haven't DONE console stuff in a long time...the only time I ever use it is if I'm testing out an algorithm that I'm putting in a larger windows app. But then again lately I've been C#-ing and creating my own OS (so I use my own write() function, now )

  4. #19
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    857
    What is the difference between printf(), sprintf() and putch()?
    -----------------
    Engineer223
    Yoshi

  5. #20
    Registered User
    Join Date
    Dec 2001
    Posts
    4
    Even though I started learning C with printf(), i've gotten more comfortable with cout << for some reason.

  6. #21
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    The book that I started C++ with used cout << so I have never used anything else. also, when I look at code which uses other thins, it looks all weird and hard to read/understand.

  7. #22
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    printf, since you have v/s/printf and you can reroute a variable argument list... which means you can do formatted output with a different output...
    hasafraggin shizigishin oppashigger...

  8. #23
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    printf...

    I'm more comfortable with the formatted printing of printf.

    And, no, C++ is not fully backwards compatible with C. When C++ branched of with OOP, C kept moving forward. I could give an example if you like.

    --Garfield
    1978 Silver Anniversary Corvette

  9. #24
    Registered User
    Join Date
    Oct 2001
    Posts
    197

    printf() !!

    printf() is much better because you have to think more when you use it. You must always know what data type you have. This can prevent errors. You can also do something like this with printf():
    Code:
    char c='a';
    printf("%d",c);
    the output is the ASCII-code for 'a'. You cannot do it with cout.

    klausi
    When I close my eyes nobody can see me...

  10. #25
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    printf() is much better because you have to think more when you use it. You must always know what data type you have. This can prevent errors. You can also do something like this with printf():

    code:--------------------------------------------------------------------------------
    char c='a';
    printf("%d",c);
    --------------------------------------------------------------------------------

    the output is the ASCII-code for 'a'. You cannot do it with cout.
    You can explicitely cast the char to a double like so;

    cout << (double)c << endl;

    As far as I know that's what printf is doing anyway

  11. #26
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    But cout << isnīt compatible to C !

    You can use your C++ compiler to program C-compatible code.
    But if you only know senseless functions like cout << thatīs very difficult!

    klausi
    When I close my eyes nobody can see me...

  12. #27
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    >>But cout << isnīt compatible to C !


    Hmm....I cant remember saying it was

  13. #28
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >sprintf just copies on string over another...

    it does formatted output to a string... i would say that is faster considering that outputting to the console is a slow job [because of the hardware updates]... whereas if it's just formatted output in memory, it's quick as can be... so i'd say that maybe sprintf is faster than printf... [don't confuse sprintf with being just a wrapper over printf because of the name... redirecting output has variations on speed depending on the media output...]
    hasafraggin shizigishin oppashigger...

  14. #29
    Registered User
    Join Date
    Dec 2001
    Posts
    15
    According to my compiler and profiler, cout is on average 5.75 milliseconds faster than printf. So much for that argument...

  15. #30
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    That's becuase printf is formatted printing. Note the formatting aspect. Time. Just means that you would have to do the formatting somewhere else in you C++ code.

    --Garfield
    1978 Silver Anniversary Corvette

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  2. Need Help with a Bowling Score Program
    By oobootsy1 in forum C++ Programming
    Replies: 6
    Last Post: 11-01-2005, 09:04 AM
  3. Double to Int conversion warning
    By wiznant in forum C Programming
    Replies: 15
    Last Post: 09-19-2005, 09:25 PM
  4. Replies: 4
    Last Post: 03-31-2003, 11:49 PM
  5. difference between cout and printf
    By Shadow12345 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2002, 09:27 AM

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