Cin.Ignore()不工作 [英] Cin.Ignore() is not working
本文介绍了Cin.Ignore()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我有一个代码:
cout< 按Enter键退出...;
cin.ignore();
此程序将执行,直到您按Enter键,然后它将退出。
现在可以看到这段代码:
int m;
cin>> m;
cout<< 按Enter键退出...;
cin.ignore();
这次输入一个数字保存为m后,程序将退出而不等待cin。
我的意思是如果你在cin.ignore之前使用cin命令,cin.ignore命令将跳过。为什么?
pre>
std :: cin.sync(); std :: cin.get();
Here I have a code:
cout << "Press Enter To Exit...";
cin.ignore();
this program will execute and will wait till you press enter and then it will exit. now see this code:
int m;
cin >> m;
cout << "Press Enter To Exit...";
cin.ignore();
this time after entering a number for saving in "m" the program will exit without waiting for cin.ignore command which waits for pressing enter.
I mean if you use cin command before cin.ignore, the cin.ignore command will skip. why? and what should I do for fixing it?
解决方案
Use this.
std::cin.sync(); std::cin.get();
这篇关于Cin.Ignore()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文