控制台在立即获得输入后立即退出
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");
#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");