Are scanf and printf allowed to be used in c++ ?
if yes -> then what are the functionality, and how to use them !
Scanf and printf in c++
Yes
scanf() :
The scanf() function in C++ is used to read the data.
ex:
int n;
scanf("%d",&n); // simply read the data from user
printf():
printf() function in C++ is used to write a formatted string
ex:
printf("hii"); // it simply print hii int n=10; printf("value of n is %d",n); // print value of n is 10
if you have further doubt feel free to ask
@asaurabh_26
is it always -> %d
in scanf and printf
also,
if I use following two commands:-
ios_base::sync_with_stdio(false);
cin.tie(NULL);
then can I ALWAYS ignore the use of printf and scanf and use cin, cout instead WITH NO DISADVANTAGE
NO, %d for integers
ios_base::sync_with_stdio(false);
This disables the synchronization between the C and C++ standard streams. By default, all standard streams are synchronized, which in practice allows you to mix C- and C+±style I/O and get sensible and expected results. If you disable the synchronization, then C++ streams are allowed to have their own independent buffers, which makes mixing C- and C+±style I/O an adventure.
Also keep in mind that synchronized C++ streams are thread-safe (output from different threads may interleave, but you get no data races).
cin.tie(NULL);
This unties cin
from cout
. Tied streams ensure that one stream is flushed automatically before each I/O operation on the other stream.