Aborting a loop in a loop without user input

In mainI give the user the opportunity to enter a command to stop the application:

while( run_processes && cin >> command_line_input ){

I would also like to stop the application elsewhere by installing run_processes = false;.

However, when I set run_processesto false, the above loop does not stop without user input.

How can I interrupt a loop correctly without user input?

+4
source share
2 answers

Unable to interrupt in a std::cinportable way.

, . poll() UNIX run_processes .

+6

cin ?

, .

bool stop = false;
std::string command;
int count = 0;
while(stop==false && std::cin>>command)
{
    ++count;
    std::cout<<count<<std::endl;
}

+1 -. run_process , , ...?

0

All Articles