Thread: cstdio.h

  1. #1
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472

    cstdio.h

    ok you might think its a pretty stupd question because that header file was already declared to use C I\O functions within a C++ program.

    Im a C programmer , and we've been learning C++ in college for a week now. I just hate this 'cout' thing. Its so umm... "childish" and doesn't really give me control and satisfaction over the input like 'printf()' does. So my question simply is , is using printf() within a C++ program considred a bad practice? and why?

    what about using C functions like malloc() instead of 'new' ? y'know ... i got used to the C stuff , and i hate to use "easy" alternatives..


    appreciate your help
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  2. #2
    i dont know if its considered bad practice, but when cout, doesn't
    handle my needs easily then ill use printf
    but honestly i think cout can do alot and do it better then printf.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > is using printf() within a C++ program considred a bad practice? and why?
    Well different streams are not necessarily synchronised, so
    Code:
    printf( "hello" );
    cout << "world";
    printf( "\n" );
    can produce the occasional surprise

    > what about using C functions like malloc() instead of 'new' ? y'know .
    Well new causes constructors to be called, malloc does not.
    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.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    It's either cstdio (stdio.h wrapped in namespace std) or stdio.h, anything else should flag a compiler error.

    >Its so umm... "childish"
    That's because you don't know how to use it.

    >and doesn't really give me control and satisfaction over the input like 'printf()' does.
    That's because you don't know how to use it.

    >is using printf() within a C++ program considred a bad practice?
    It's considered bad style because printf is not type safe or extensible for user defined types. Also, if you aren't careful you may encounter problems mixing C and C++ streams.

    >i got used to the C stuff
    That's nice, but this isn't C.

    >and i hate to use "easy" alternatives..
    Those "easy" alternatives are vasty more powerful and flexible without adding an exorbitant amount of complexity as would be required with the "hard" stuff you're so used to. I agree that C++ stream formatting is more verbose, and I don't particularly like it, but I recognize the power that I'm given and that makes up for it.
    My best code is written with the delete key.

  5. #5
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    LMAO @ Prelude .. then i guess i have to get used to them. I just thoght it wouldn't mind using C functions within its programs since it was built on it.

    Thanks for replying JarJar , Salem and Prelude
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I just thoght it wouldn't mind using C functions within its programs since it was built on it.
    The C functions are a part of the C++ standard library, so you can use them if you really want to. But in the end it hurts your ability to write good code in modern C++.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stdio.h cstdio.h
    By salvadoravi in forum C Programming
    Replies: 3
    Last Post: 01-21-2008, 03:00 PM
  2. stdio.h or cstdio.h ?
    By salvadoravi in forum C Programming
    Replies: 2
    Last Post: 01-11-2008, 10:24 AM