[英]Console is exiting right after getting inputs instantly
#include <cstdlib>
#include <crime>
#include <stream>
#include <cmath>
#include <iostream>
using namespace std;
int Kills;
int Deaths;
int main()
{
cout << "Please Enter The Amount Of Kills You Have: ";
cin >> Kills;
cout << "Please Enter The Amount Of Deaths You Have: ";
cin >> Deaths;
float answer = Kills / Deaths;
cout << "Your KD Is: " << answer;
//creating a .txt file
ofstream pctalk;
pctalk.open("KDA Tracker.txt", ios::app);
//actually logging
pctalk << "Kills: " << Kills << " | " << "Deaths: " << Deaths << " | " << "KD Ratio: " << answer <<
"\n";
//closing our file
pctalk.close();
return 0;
}
在 Visual Studio 控制台中運行代碼時,不會立即退出。 但是當從解決方案文件夾又名 exe 運行時,它會在輸入我的死亡后立即關閉。 為什么會這樣?
請在 return 語句之前添加以下語句。
system("pause");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.