当使用VS2017执行下列输入输出程序时 ,控制台直接闪退:
#include<iostream>
using namespace std;
int main()
{
int carrots;
carrots = 25;
cout << "I have ";
cout << carrots;
cout << "carrots";
cout << endl;
carrots -= 1;
cout << "Crunch, Crunch. Now I have " << carrots << " carrots!" << endl;
return 0;
}
解决办法:
1.在程序返回值之前加入system(“pause”);语句。
2.在该执行的项目上点击右键选择“链接器”,然后选择“系统”,在右面的子系统中选择控制台。