Note:The code works fine and the o/p is desired too I just wanna know does cout displays into the screen or writes to ostream,and if it writes to ostream when does the ostream gets displayed .
I have following c++ code
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main()
{
string str,buffer;
while(cin)//take input forever
{
cin>>str;
if(str =="Quit")//unless the word is Quit
{
break;
}
else{
if(buffer != str)//donot repeat the words
{
cout<<str<<" ";
}
}
buffer = str;
}
return 0;
}
Why is not str
being displayed everytime str != "Quit"
?Is it because of the fact that cout
doesnot display something in the screen it just writes or sends them to the ostream and ostream is responsible for something to be displayed.
If that is true,When does the ostream gets displayed in the screen -after inputting to the stream is finished?