cin vs. scanf

I´m (obviously new to C++) and reading more and more material in the web I´ve come to notice the coexistence of two similar sintaxes:

cout << "text"; vs. printf("text");

cin >> variable; vs. scanf("%var_type",&var_name);

#include<iostream> vs. #include<iostream.h>

What´s all this about?
Are theese interchangeable?
Can they coexist in the body of an algorithm?
Which one do you suggest I use/master?

Thank you!!!

C++ got printf and scanf from C. I would say cout and cin is recommended in C++.

None of the standard headers have a .h extension so <iostream> is correct. Some old compilers force you to use <iostream.h> but then it's probably better to switch to a more up-to-date compiler.
I use printf so that I can format my vars.

int a=3;
float b = 12345.6789
int c = 65

printf("/n/nThis is a float %4.3f, /nThis is an int %d, /n/t This is a hex val %#x /n/n " a,b,c,);

and when using files, I can use the exact same formats with FSCANF & FPRINTF

Too, I can easily place these statements into subrt'ns for fast & quik debugging as flags to show, not only whare I am in the code, but also what the actual value of vars are ( rather than assumed values)

But, hey, that's just me.

and, "yes" I'm left-over from K&R's "C"





Last edited on
Topic archived. No new replies allowed.