View Poll Results: the most annoying error

Voters
9. You may not vote on this poll
  • syntax

    5 55.56%
  • precompiled header directive

    1 11.11%
  • undeclared identetive

    1 11.11%
  • multitasking

    2 22.22%

Thread: printf and cout

  1. #16
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    cout is only as type safe as you want it to be.

    Example
    Code:
    int whatever = -1;
    std::cout << *(std::string *)whatever << std::endl;
    Though it seems like I had to do a lot of work to break cout, in the real world this sort of thing comes up every once in a while.

  2. #17
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    >but I think that the cout is more readable.

    cout is more readable for unformatted debug output. Once you need to do heavy formatting printf gets more comfortable.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #18
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by master5001
    cout is only as type safe as you want it to be.

    Example
    Code:
    int whatever = -1;
    std::cout << *(std::string *)whatever << std::endl;
    Though it seems like I had to do a lot of work to break cout, in the real world this sort of thing comes up every once in a while.
    That's still promoting type-safety -- you have to typecast it in order to get it to do something like that. When using printf it's a matter of using a different format descriptor.

  4. #19
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    cout is more readable, but printf produces smaller binaries.
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  5. #20
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Jaguar
    cout is more readable, but printf produces smaller binaries.
    Opinion and implementation dependant

    From Stroustrup himself

    Why is the code generated for the "Hello world" program ten times larger for C++ than for C?
    It isn't on my machine, and it shouldn't be on yours. In fact, the object code for the C++ version of the "hello world" program is smaller than the C version on my machine. There is no language reason why the one version should be larger than the other. It is all an issue on how the implementor organized the libraries. If one version is significantly larger than the other, report the problem to the implementor of the larger.
    Last edited by Polymorphic OOP; 12-19-2002 at 09:52 AM.

  6. #21
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    I'm more C++ programmer and not C programmer

    So, my favourite: cout

    C++: cout
    C: printf

    But printf is very nice *g

  7. #22
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Discussed long enough... closed.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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 vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 04:26 PM
  5. difference between cout and printf
    By Shadow12345 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2002, 09:27 AM