对于有些程序return前面加cin.get(),还是会闪退,大家怎么办的
c++吧
全部回复
仅看楼主
level 12
441932250 楼主
//读入一组数据,直到读入结束符(Ctrl+z), 得出负数的个数。
#include<iostream>
using namespace std;
int main()
{
cout<<"Please input a list number:"<<endl;
int amount=0,value;
while(cin>>value)
if(value<0)
++amount;
cout<<"fushu de ge shu is "<<amount<<endl;
//cin.get(); 解决不了闪退问题。
return 0;
}
//我用的编辑器是VS2012,一般程序闪退,加cin.get(),就可以。可是这个加了也不行。大家有没有什么好办法?
2014年01月11日 13点01分 1
level 9
加两个
2014年01月11日 13点01分 2
试过了,没有效果,如果是有明确数目的cin输入,加2个就可以,可是这个程序没有具体输入数目,加了没有效果。
2014年01月11日 13点01分
level 13
while(1);
再不行就atexit( [ ] { while(1); } );
2014年01月11日 13点01分 3
while(1),这个不是死循环了么?这个最后有办法正常退出么?
2014年01月11日 13点01分
回复 441932250 :cmd窗口右上角有╳
2014年01月11日 13点01分
level 10
system("pause");
报错的话加 #include <cstdlib>
2014年01月11日 13点01分 4
非常感谢,试过了,vs2012完美支持。
2014年01月11日 13点01分
level 10
缓冲区没清
2014年01月11日 13点01分 5
level 10
加上cin.ignore(100); 在cin.get();前面
2014年01月11日 13点01分 6
不管用啊
2015年02月04日 06点02分
level 12
貌似应该这样
cin.sync();
cin.get();
2015年02月04日 07点02分 8
咱建了几个C++群,欢迎感兴趣的伙伴加入:http://hi.baidu.com/bbdai[滑稽]
2015年02月04日 07点02分
1