控制台立即获得输入后立即退出

问题描述 投票:0回答:1
#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控制台中运行代码时不会立即退出。但是从解决方案文件夹aka exe运行时,它在输入我的死亡信息后立即关闭。为什么会这样?

c++ console fstream
1个回答
0
投票

请在返回语句之前放置以下语句。

system("pause");
© www.soinside.com 2019 - 2024. All rights reserved.