1. 程式人生 > >使用VS2017輸入輸出時出現控制檯閃退解決方法

使用VS2017輸入輸出時出現控制檯閃退解決方法

當使用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.在該執行的專案上點選右鍵選擇“連結器”,然後選擇“系統”,在右面的子系統中選擇控制檯。