Reputation: 353
I am confused what happens when another cin comes does the previous input is flushed?
That is when we hit enter for the next input there is \n
but what happens to the input?
is it still in the input stream?
Another doubt is, when there is already something in the input stream then it does not take user input so in that case does it assign whatever is there in input stream to the variable? The code is given here
string playername,food,age;
cin>>playername;
cout<<"what is your age";
cin>>age;
cout<<"your fav food";
cin>>food;
Now if I give playername
as "rahul singh" it will give "rahul" to the playername but now singh is there in the input stream so does it assign singh to age
? Or what happens I am not aware
Upvotes: 1
Views: 562
Reputation: 238491
I am confused what happens when another cin comes does the previous input is flushed?
No, input is not flushed in that case. Everything that was not extracted will still remain in the buffer.
Input buffer can be flushed explicitly using std::cin.ignore(INT_MAX);
.
so in that case does it assign whatever is there in input stream to the variable?
It will extract from the existing input in the buffer.
but now singh is there in the input stream so does it assign singh to age?
Yes.
Upvotes: 1