C++ 为什么我的程序不能在Visual Studio 2019之外输出我想要的信息?
我编写了一个程序,为用户提供一些关于减肥的信息,以及如何达到特定目标,我要求用户输入一些信息。我正处于这样一个阶段,我可以开始实现一些函数,使主函数变得更好一些,但在解决这个问题之前,我不想继续 它在Visual Studio中运行得很好,完美地输出了最后一部分,但是如果我尝试运行build文件夹中的.exe进行调试或发布,它只会在告诉用户他们想要的信息之前退出程序 不过,我不确定为什么会发生这种情况,因为它不会给我任何构建错误或编译器错误。下面是.exe跳过的代码:C++ 为什么我的程序不能在Visual Studio 2019之外输出我想要的信息?,c++,C++,我编写了一个程序,为用户提供一些关于减肥的信息,以及如何达到特定目标,我要求用户输入一些信息。我正处于这样一个阶段,我可以开始实现一些函数,使主函数变得更好一些,但在解决这个问题之前,我不想继续 它在Visual Studio中运行得很好,完美地输出了最后一部分,但是如果我尝试运行build文件夹中的.exe进行调试或发布,它只会在告诉用户他们想要的信息之前退出程序 不过,我不确定为什么会发生这种情况,因为它不会给我任何构建错误或编译器错误。下面是.exe跳过的代码: cout <<
cout << "Choose your rate at which you'd like to meet your goal! " <<
"\n 1. Fast\n 2. Medium\n 3. Slow" << endl;
int uRate;
cin >> uRate;
//This bit of code it executes, and the user inputs their rate, which
//assigns the value to the switch statement for it to determine it's case.
double time = uWeight - uGoalWeight;
double fastrate = (uWeight * 0.01);
double mediumrate = (uWeight * 0.0075);
double slowrate = (uWeight * 0.005);
int newTime;
switch (uRate) {
case 1:
newTime = time / fastrate;
cout << "Your time in weeks to reach your goal is : " << newTime << " weeks." << endl;
cout << "You'd have to lose " << fastrate << " lbs per week to meet this goal!" << endl;
cout << "Remember, your optimal goal weight would be: "
<< uGoalWeight << " lbs!" << endl;
break;
case 2:
newTime = time / mediumrate;
cout << "Your time in weeks to reach your goal is : " << newTime << " weeks." << endl;
cout << "You'd have to lose " << mediumrate << " lbs per week to meet this goal!" << endl;
cout << "Remember, your optimal goal weight would be: "
<< uGoalWeight << " lbs!" << endl;
break;
case 3:
newTime = time / slowrate;
cout << "Your time in weeks to reach your goal is : " << newTime << " weeks." << endl;
cout << "You'd have to lose " << slowrate << " lbs per week to meet this goal!" << endl;
cout << "Remember, your optimal goal weight would be: "
<< uGoalWeight << " lbs!" << endl;
break;
基本上,这段代码不会显示在release/debug.exe文件中。只要在VS2019的版本中调试或运行,其他一切都可以正常工作。我需要显示这些信息,因为这是应用程序编码的全部原因。你确定这不是控制台窗口立即关闭问题的原因之一吗?如果你只需单击一个可执行文件,它在不到一秒钟内完成,你甚至可能根本看不到它的窗口。请记住,操作系统通常不会为已完成执行的程序打开窗口。请从命令行运行程序。你会看到输出。是的,它一直接受输入,直到你选择减肥率。一旦您输入1、2或3来选择费率,它就会关闭。可能会重复