What is the significance of this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the significance of this code?

#include<iostream> #include<conio.h> using namespace std; int main() { char c; cin.get(c); while(c!='\n') { cout<<c; cin.get(c); } }

12th Jun 2020, 8:42 AM
Prashant Pant
Prashant Pant - avatar
1 Answer
0
I sort of un understood what is going on here. My fault was I was entering only one input. Try inputting a sentence. When you input a sentence, here is what happens. "cin" function assigns the first character of the sentence to c. And the program enters the loop. In the loop, the cout function outputs the character that was stored in c. And then again in another statement, the cin is taking another character of the sentence, and it again printed until the sentence is broken by ENTER (\n). In my opinion, I think when we input the sentence, the letters are stored in stream and they are available for cin to input character by character and for cout to output character by character. Well, this is what I understood. Correct me if I am wrong.
12th Jun 2020, 8:53 AM
Prashant Pant
Prashant Pant - avatar