C++: Read from stdin as data is written into pipe
问题 I have two C++ programs: one that prints a message to stdout, and the other that listens to stdin and prints all content from the stream. They are named out and in respectively. out.cpp: #include <iostream> using namespace std; int main() { cout<<"HELLO"; usleep(1000000); cout<<"HELLO"; } in.cpp: #include <iostream> using namespace std; int main() { string input; while(cin>>input) { cout<<input; } } As it currently stands, piping the data from out to in waits for two seconds, then prints