I have a c++ code like this:
#include<iostream>
using namespace std;
int main()
{
char str[20];
while(true)
{
cin>>str;
cout<<"Your input is "<<str<<endl;
}
}
and when I use linux shell script like :
echo t|./test
it shows result I don't want to see: enter image description here
it just come out infinite "Your input is t"
I guess it's because the thing in "cin" doesn't disappear. I add these two lines but it doesn't work:
cin.clear();
cin.ignore(1024,'\n');
What I want is that it outputs one sentence, and waits for my next input. Just like I do "./test"