+ 2
C++; What is the difference between scanf()/printf and cin/cout ?
Can someone explain what is the difference between scanf()/printf and cin/cout. Can someone give the same codes for both? I need simple explanation for beginner :)
12 Respostas
+ 2
Use the Search bar
+ 2
scanf() and printf() mostly you find in c language
While cin & cout mostly find in C++ language.
scanf() and cin takes user input in respectively in C & C++
While printf() and cout used for showing output respectively in C and C++
Edited :
Beginners explanation
https://code.sololearn.com/c2sp4SP1kA07/?ref=app
https://code.sololearn.com/cmjihzVTcrXb/?ref=app
+ 2
MichaĆ D
She ask for beginner explanation & i see she even not started c/c++ course : )
+ 2
Mr. Rahul i am 'she' ;p :) and yes i didn't start but i have c++ on my studies :)
Every way to learn is good;) Thank you all for helpful anserws :)
+ 1
Mr. Rahul + scanf/printf are faster than cin/cout, as you have to give them "hints" such as declare data type which will be read or printed, when cin/cout have to figure it out by themselves depending on variable type
+ 1
Ohhđ€
Martyna T
Now i edited my comment..
I think u able to understand your question from above example
Hope u to learn c++ well
Have a good day đ
+ 1
in c++ printf and scanf is taken from c.These functions perform input output oparations. These are in cstdio or stdio.h header file.
scanf(â%dâ,&x); //takes input and stores it in x
printf(âNum = %dâ,x)// prints x at %d position
cout and cin are objects of ostream and istream class respectively. These are in âiostreamâ header file and defined under std namespace. << and >> are overloaded.
cin>>x; //takes input from user and stores in x
cout<<x;//prints x to console
On a high level both of them are wrappers over read() system call, just syntactic sugar. The only visible difference is that scanf() has to explicitly declare the input type, whereas cin has the redirection operation overloaded using templates. This causes performance hit of 5x for cin.
It turns out that iostream makes use of stdioâs buffering system. So, cin wastes time synchronizing itself with the underlying C-libraryâs stdio buffer.
for more detailed difference you can refer this s:https://stackoverflow.com/questions/2872543/printf-vs-cout
+ 1
Input vs output
0
I know;) and i tried:)
0
This should be a good explaination
https://www.google.com/amp/s/www.geeksforgeeks.org/cincout-vs-scanfprintf/amp/
0
Here also good explanation
Check out Freeđ„
https://www.studytonight.com
0
Thank You all :)