cin.get()是非阻塞的 [英] cin.get() is non-blocking
本文介绍了cin.get()是非阻塞的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有与链接的问题相同的问题。运行该程序后,控制台窗口(在VS 2010中)立即消失。我使用cin.get();在主要功能的末尾,但问题仍然存在。对可能的原因有任何想法吗?您可以在main中检出代码:
I have the same problem as mentioned in the linked question. The console window (in VS 2010) disappears immediately after running the program. I use a cin.get(); at the end of the main function, but the problem still remains. Any idea about the possible reason? You can check out the code in main:
int main()
{
const int arraysize = 10;
int order;
int counter;
int a[arraysize] = {2,6,4,45,32,12,7,33,23,98};
cout<<"Enter 1 to sort in ascending order\n"
<<"Enter 2 to sort in descending order\n";
cin>>order;
cout<<"Data items in original order\n";
for(counter=0;counter<arraysize;counter++){
cout<<setw(4)<<a[counter];
}
switch (order){
case 1: cout<<"\nData items in ascending order\n";
selectionSort(a, arraysize, ascending);
break;
case 2: cout<<"\nData items in descending order\n";
selectionSort(a, arraysize, descending);
break;
default: return 0;
}
for(counter=0;counter<arraysize;counter++){
cout<<setw(4)<<a[counter];
}
cout<<endl;
cin.get();
return 0;
}
链接: Windows上的C ++-控制台窗口只是闪烁而消失。
推荐答案
我的猜测是
default: return 0;
开始执行。
编辑:
是的,那不是问题。阅读此。
You're right, that's not the issue. Read this.
快速解决方法是:
cout<<endl;
cin.ignore(); // <---- ignore previous input in the buffer
cin.get();
但是您可能需要阅读该文章以获取有关该行为的更多信息。
But you might want to read the article for further info on the behavior.
这篇关于cin.get()是非阻塞的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文