+ 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 :)

17th Jan 2021, 5:45 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar
12 Antworten
+ 2
Use the Search bar
17th Jan 2021, 5:46 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 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
17th Jan 2021, 7:38 PM
Mr. Rahul
Mr. Rahul - avatar
+ 2
Michał D She ask for beginner explanation & i see she even not started c/c++ course : )
17th Jan 2021, 7:53 PM
Mr. Rahul
Mr. Rahul - avatar
+ 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 :)
18th Jan 2021, 7:55 AM
Martyna Tomaszewska
Martyna Tomaszewska - avatar
+ 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
17th Jan 2021, 7:50 PM
Michal Doruch
+ 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 😊
18th Jan 2021, 9:02 AM
Mr. Rahul
Mr. Rahul - avatar
+ 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
18th Jan 2021, 2:42 PM
mahesh hegde
mahesh hegde - avatar
+ 1
Input vs output
18th Jan 2021, 11:20 PM
Sonic
Sonic - avatar
0
I know;) and i tried:)
17th Jan 2021, 5:48 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar
17th Jan 2021, 7:33 PM
Michal Doruch
0
Here also good explanation Check out Free💥 https://www.studytonight.com
19th Jan 2021, 4:47 AM
Sagar Maurya
Sagar Maurya - avatar
0
Thank You all :)
23rd Jan 2021, 2:14 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar