Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在用户未输入输入的情况下中断cin while循环_C++_Linux_While Loop_Interrupt_Cin - Fatal编程技术网

C++ 在用户未输入输入的情况下中断cin while循环

C++ 在用户未输入输入的情况下中断cin while循环,c++,linux,while-loop,interrupt,cin,C++,Linux,While Loop,Interrupt,Cin,在main中,我允许用户输入命令来停止应用程序: while( run_processes && cin >> command_line_input ){ 我还想通过设置run\u processs=false在别处停止应用程序 但是,当我将run\u processs设置为false时,如果用户没有输入,上述循环不会停止 如何在用户不输入输入的情况下正确中断循环 cin不一定要依赖用户的输入吗 继续 是的,用户必须输入每个循环的输入 bool stop = fal

main
中,我允许用户输入命令来停止应用程序:

while( run_processes && cin >> command_line_input ){
我还想通过设置
run\u processs=false在别处停止应用程序

但是,当我将
run\u processs
设置为
false
时,如果用户没有输入,上述循环不会停止

如何在用户不输入输入的情况下正确中断循环

cin不一定要依赖用户的输入吗 继续

是的,用户必须输入每个循环的输入

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

std::cout不可能以便携方式中断
std::cin


但是,您可以解析为不可移植的解决方案,例如手动
poll()
在UNIX系统上的标准输入,并在轮询时检查
运行\u进程

显示更多代码:在另一个boost线程中将其设置为false的位置和方式?@quantdev。我很抱歉遗漏了一个关键细节,我希望在没有用户输入的情况下停止循环。我已确认
运行\u进程
是正确的ly正在设置。
cin
是否不一定取决于用户输入,而
将继续进行?非常感谢您!如果您创建另一个调用
cin>>命令行输入的线程(然后将字符串发送到主线程),然后您可以在主线程中决定不等待从
cin
读取线程。我认为不可能以可移植的方式中止
cin>>命令行输入调用本身。