-
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 :)
-
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.
-
> 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.
-
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. :)
-
LMAO @ Prelude .. then i guess i have to get used to them:p. 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 :)
-
>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++.